我在使用 getElementbyId 时遇到问题,如下所示:
<script type="text/javascript">
<!--
function show_links(locale) {
var box = document.getElementById(locale);
if(box.style.display == "none") {
box.style.display = "inline";
}
else {
box.style.display = "none";
}
}
//-->
</script>
<div class="link"><strong><a href="javascript:show_links(test);">Test</a></strong></div>
<div class="test"> Blah blah blah. This content comes and goes. </div>
所以你有代码。当我单击“测试”链接时,它应该隐藏“等等等等文字”。再次单击时,它应该显示。但是,我有一个奇怪的问题。我通过调试器处理了代码,似乎该行var box = document.getElementById(locale);
无法正常工作。box
被设置为空。谁能理论化为什么?