WD1X.COM - 问答一下,轻松解决,电脑应用解决专家
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win11Linux
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascript服务器
PHP教程CSS教程XML教程

js给下拉框select 赋值

更新时间:2012-09-26 11:09 作者:佚名点击:

<!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=gb2312" />
<title>网页特效给下拉框select 赋值</title>

</head>

<body>

  <select name="name" onchange="test(this);">
<option value="1">美国</option>
<option value="2">中国</option>
</select>
<input type="text" name="fax" id="fax" size="20">
<script>
function test(o) {
 var index = o.selectedindex;
 var text = o.options[index].text;
 document.getelementbyid("fax").value = text;
}

function addvalue()
{
 document.all.aaa.options[document.all.aaa.options.length]=new option('aaaaa','vvv')

}
 </script>

 

<!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=gb2312" />
<title>网页特效给下拉框select 赋值</title>

</head>

<body>

<select name="name" onchange="test(this);">
<option value="1">美国</option>
<option value="2">中国</option>
</select>
<input type="text" name="fax" id="fax" size="20">
<script>
function test(o) {
 var index = o.selectedindex;
 var text = o.options[index].text;
 document.getelementbyid("fax").value = text;
}

function addvalue()
{
 document.all.aaa.options[document.all.aaa.options.length]=new option('aaaaa','vvv')

}
 </script>

 
<select name="aaa" onchange="alert(this.options[selectedindex].aaa)">
<option aaa="aaa">update8.com</option>
<option aaa="bbb">www.update8.com</option>
<option aaa="ccc">经济风暴</option>
</select>
<a href="网页特效:addvalue();">增加值</a>

//方法三

//创建一个option    

 

  var ooption = document.createelement("option");   
            //将option添加到城市选择框中   
             document.getelementbyid("sp").options.add(ooption);   
             document.getelementbyid("sp").options[0].selected=true;   
            //为option赋值   
             ooption.innertext =p[sp.value][i];   
             ooption.value =p[sp.value][i];   

 

</body>
</html>

顶一下
(0)
0%
踩一下
(2)
100%
------分隔线----------------------------
你可能感兴趣的内容