首页 > 网站 > WEB开发 > 正文

增加页面中下拉列表框中的列表项目

2024-04-27 15:11:30
字体:
来源:转载
供稿:网友
效果如下:

图片

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>增加页面中下拉列表框中的列表项目</title></head><script language="javascript" type="text/Javascript">var i,txt,val;window.onload = function() {	var btnobj = document.getElementById("testbtn");	if(btnobj)	{		btnobj.onclick = function() { InsertItem() };	}	i=0;}function InsertItem(){	i++;	var testlistobj = document.getElementById("testlist");	var option;		txt = "新增下拉列表项目" + i.toString();	val = txt + i.toString();		option = new Option(txt, val);	if(testlistobj)	{		testlistobj.options.add(option);	}}</script><body><select id="testlist"></select><input id="testbtn" type="button" value="增加列表项目"></body></html>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表