javascript select
<select name="gender" style="width:200; margin-left:50px;" id="Yearselect"><script type="text/javascript"> var yselect=document.getElementById("Yearselect") var year = new Date() var nYear = year.getFullYear() while(nYear >= 1970 ) { yselect.options.add(new Option(nYear + "年", nYear-1970))//这里的年怎么就加不上? nYear-- }</script></select>
怎么个意思?是年份数值加不上还是 otpion项添加不上
yselect.options.add(new Option(nYear,nYear-1970))//年份可以显示如2013,就是想在后面加个“年”字
yselect.options.add(new Option(nYear + "年",nYear-1970))//连年份都不显示,压根什么都没有
<html><head></head><body> <select name="gender" style="width:200; margin-left:50px;" id="Yearselect"> </select></body><script type="text/javascript"> var yselect=document.getElementById("Yearselect") var year = new Date() var nYear = year.getFullYear() while(nYear >= 1970 ) { yselect.options.add(new Option(nYear + "年", nYear-1970))//这里的年怎么就加不上? nYear-- } </script></html>
我加了一个
就好了