源码:<!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>无标题文档</title>
<link rel="stylesheet" type="text/css" href="bd.css" />
</head>
<script language="javascript">
var opttext= new Array(100);
var optvalue=new Array(100);function change(object){
opt=object.options[object.selectedIndex];
alert(opt.value+" : "+opt.text);
}
for(i=0;i<opttext.length;i++)
{
opttext[i]=i;
optvalue[i]=i;
}function option(){
var opt;
var start;
var end;
for(i=1;i<opttext.length;i++)
{ opt=new Option();
opt.text=opttext[i];
opt.value=optvalue[i];
selShow.options.add(opt);
}
end=new Date();
}</script>
<body>
<form action="" method="post"><select name="selShow" id="selShow" ><option value="0">0</option></select>
</form></body>
</html>
去掉form标签,则可以执行js函数,加上form标签,则不执行JS函数,在线求高手指教。谢谢了。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="bd.css" />
</head>
<script language="javascript">
var opttext= new Array(100);
var optvalue=new Array(100);function change(object){
opt=object.options[object.selectedIndex];
alert(opt.value+" : "+opt.text);
}
for(i=0;i<opttext.length;i++)
{
opttext[i]=i;
optvalue[i]=i;
}function option(){
var opt;
var start;
var end;
for(i=1;i<opttext.length;i++)
{ opt=new Option();
opt.text=opttext[i];
opt.value=optvalue[i];
selShow.options.add(opt);
}
end=new Date();
}</script>
<body>
<form action="" method="post"><select name="selShow" id="selShow" ><option value="0">0</option></select>
</form></body>
</html>
去掉form标签,则可以执行js函数,加上form标签,则不执行JS函数,在线求高手指教。谢谢了。
document.getElementById("selShow").options.add(opt);body onload="option()"
或者将脚本放到select下面
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
var opttext = new Array(100);
var optvalue = new Array(100); function change(object) {
opt = object.options[object.selectedIndex];
alert(opt.value + " : " + opt.text);
}
for (i = 0; i < opttext.length; i++) {
opttext[i] = i;
optvalue[i] = i;
} function option() {
var opt;
var start;
var end;
for (i = 1; i < opttext.length; i++) {
opt = new Option();
opt.text = opttext[i];
opt.value = optvalue[i];
document.getElementById("selShow").options.add(opt); }
end = new Date();
}</script>
<body onload="option()">
<form action="" method="post">
<select name="selShow" id="selShow">
<option value="0">0</option>
</select>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form action="" method="post">
<select name="selShow" id="selShow" onchange="change(this)"><option value="0">0</option></select>
</form>
<script language="javascript">
var opttext= new Array(100);
var optvalue=new Array(100);
function change(object)
{
opt=object.options[object.selectedIndex];
alert(opt.value+" : "+opt.text);
}
for(i=0;i<opttext.length;i++)
{
opttext[i]=i;
optvalue[i]=i;
}
function option()
{
var opt;
var start;
var end;
for(i=1;i<opttext.length;i++)
{
opt=new Option();
opt.text=opttext[i];
opt.value=optvalue[i];
document.getElementById('selShow').options.add(opt);
}
end=new Date();
}
window.onload = option();
</script>
</body>
</html>
经测试,这样是可行的。
不知道你是不是想要这样的效果?