我有如下用的getElementById一個問題:問題與的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
正被設置爲空。任何人都可以爲什麼理論化?
把測試放在引號 – 2009-11-01 02:21:30