如何实现下拉框动态绑定年份????
如题,如何在下拉框中动态绑定年份,也就是绑定从一定年份到今年这个范围。例如:1990-2009,起始年份可以固定,但是终止年份必须是动态改变的。希望高手帮帮忙!先谢了!
[解决办法]
只能用JS实现了,对应了IE,FF,GOOGLE,其它的没测试,结束年请修改红色部分,也可以绑定。
<html><head><script type="text/javascript"> var beginYear = 1990; function checkIE() { var name = navigator.appName; alert(name); if (name == "Microsoft Internet Explorer") return 1; else if (name == "Netscape") return 2; } function setIEValue() { var value = document.getElementById('value').value; for (i = beginYear; i <= value; i++) { var op = document.createElement("option"); op.text = i; op.value = i; document.getElementById('year').add(op); } } function setFFValue() { var value = document.getElementById('value').value; var out = ''; for (i = beginYear; i <= value; i++) { out += ('<option>' + i + '</option>'); } document.getElementById('year').innerHTML = out; } var flg = checkIE(); if (flg == 1) window.onload = setIEValue; else if (flg == 2) window.onload = setFFValue;</script></head><body> <select id="year"></select><input id="value" type="hidden" value="[color=#FF0000]2005[/color]" /></body></html>
[解决办法]
gocreate proc GetYear(@StartYear int)asbegin declare @table table ([Year] int) while (@StartYear<=year(getdate())) begin insert into @table select @StartYear set @StartYear=@StartYear+1; end select * from @tableend/*测试*/exec GetYear 1990 /*结果Year-----------19901991199219931994199519961997199819992000200120022003200420052006200720082009*/