<!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>
|