如何使用javascript在下拉列表中保留所选值
嗨,在下面的代码中,我需要保留要显示的选定值.但如果我选择并更新页面,列表框总是显示索引值"SELECT".我希望它显示选定的值.我必须在下面的代码中进行哪些更改
选择 | 换行 | 行号
- <select name="year" id="year<%=gfimCount%>" class="textbox" style="width:60px;" >
- <option value="select">Select</option>
- <script type="text/javascript">
- var YearList = 6; // number of "year" selections.
- var year = new Date().getFullYear();
- for(var i=5;i>0;i--){
- var previousyr=year-i;
- document.write('<option value="' + previousyr + '">' + previousyr + '</option>');
- }
- //document.write('<option selected="true" value="'+previousyr+'">'+previousyr+'</option>');
- for(var i=0;i<YearList;i++){
- var currentyr = year + i;
- document.write('<option value="' + currentyr + '">' + currentyr + '</option>'); //document.getElementBbyId(<%="currentyr"%>).value;
- }
- //document.write('<option selected="true" value="'+currentyr+'">'+currentyr+'</option>');
- </script>
- </select>