加参数defer,加载完毕再执行,alert 起了这个作用。
<select name="s1">
</select>
<script defer language="javascript">
var f=document.all.s1;
var y1=2007;
for(var i=2003;i<=2008;i++){
//if(i==y1) alert(i);
var opt=new Option(i,i,false,(i==y1));
f[f.options.length]=opt;
}
</script>
<select name="s1">
</select>
<script defer language="javascript">
var f=document.all.s1;
var y1=2007;
for(var i=2003;i<=2008;i++){
//if(i==y1) alert(i);
var opt=new Option(i,i,false,(i==y1));
f[f.options.length]=opt;
}
</script>
When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering.
程序下载完后再进行解析和执行