2
下面的代碼財產「的className」顯示錯誤"Uncaught TypeError: Cannot set property 'className' of null"
遺漏的類型錯誤:無法設置的空
<style>
.deactive { height:250px; }
.active { height:150px; }
</style>
<script>
function click(div) {
document.getElementById('div').className = 'active';
}
</script>
<a href="#" onclick="click(Division);">
<div id="Division" class="deactive">
<!--Division contents-->
</div>
</a>
我爲錨標籤的單擊事件試圖師js函數的通ID ..我想改變劃分的類名, 幫我找出錯誤..因爲你的文檔中,你有id爲"div"
所以document.getElementById('div')
是null
沒有出現元素
此處的div一定不能用引號引起來?但是你自己說過,這個ID沒有元素。那他爲什麼要用它? –
函數內的'div'是當您調用該函數時其值爲'「division」'的變量...嘗試查看https://developer.mozilla.org/en-US/docs/Web/ JavaScript /指南/功能 – fcalderan
非常感謝! – chriz