【发布时间】:2013-07-23 12:52:47
【问题描述】:
我想选择带有链接的组合的索引。
我试过这个:
<script>
eval(document.location.hash.substring(1));
function poke(num, zat) {
var selObj = document.getElementById('okey');
selObj.selectedIndex = num - 1;
var selObj = document.getElementById('nope');
selObj.selectedIndex = zat - 1;
}
</script>
<select id="okey">
<option>one</option>
<option>two</option>
<option>three</option>
<option>four</option>
<option>five</option>
</select>
<select id="nope">
<option>one</option>
<option>two</option>
<option>three</option>
<option>four</option>
<option>five</option>
</select>
<button onclick="eval(document.location.hash.substring(1));">okey</button>
按钮工作正常,但是当我尝试加载页面时,它显示错误。
错误是这样的:
Uncaught TypeError: Cannot set property 'selectedIndex' of null
我能怎么做?代码是一样的。但是负载不工作,按钮工作。嗯?
【问题讨论】:
-
为什么要在“onclick”处理程序中评估代码?
-
因为,我想确定代码是否正常工作。 :)
-
我不确定你如何通过评估代码来实现这一点:)
-
我找到了,谢谢你的帮助:)
标签: javascript select load selectedindex