我有一个 javascript 下拉列表,它显示所选值和其他值,但所选值在下拉列表中显示 2 次,它应该只显示 1 次。请任何人帮助我纠正问题。例如。 如果只有 3 个值 2013、2014.2015,我选择 2013 但它显示 2013-选定的值 2013年 2013年 2014年 2015年
<script type="text/javascript">
function autoYear() {
var time = new Date();
var year = time.getYear();
if (year < 1900) {
year = year + 1900;
}
var date = year - 1; /*change the '25' to the number of years in the past you want to show */
var future = year + 10; /*change the '10' to the number of years in the future you want to show */
document.writeln ("<form><select id='year_<?php echo $row->id ?>' name='year_<?php echo $row->id ?>' ><option value=\"\"><?php echo $row->year; ?>");
do {
date++;
document.write ("<option value=\"" +date+"\">" +date+ "");
}
while (date < future)
document.write ("</select></form>");
}
</script>
<script type="text/javascript">
autoYear();
</script>
最佳答案
看来您没有关闭 <option>
标签。
此外,正如上面评论中提到的,有比用 document.write
手动写出标签更好的方法来做到这一点。 。以这种方式手动编写 HTML 时更容易产生错误。
关于javascript - 下拉列表中选定的值在下拉列表中显示两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19698738/