日期:2014-05-16  浏览次数:20267 次

form表单内不能调用JS函数
源码:

<!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函数,在线求高手指教。谢谢了。

------解决方案--------------------
document.getElementById("selShow").options.add(opt);
------解决方案--------------------
selShow.options.add(opt); 改一下 
 document.getElementById("selShow").options.add(opt);

body onload="option()"
或者将脚本放到select下面
------解决方案--------------------
selShow.options.add(opt);>>document.getElementById("selShow").options.add(opt);