0
時無法設置屬性'href'的undefined或null引用問題是這樣的:我嘗試動態更改在body - onload中執行的函數CheckCookie
中的LINk的innerHTML和href。下面是函數:異常當
function checkCookie()
{
var username = getCookie("username");
if (username != null && username != "")
{
document.getElementById("firstlink").href = "http://localhost:8080/newLogIN/probalassfinalwithoutstyle.html";
document.getElementById("firstlink").innerHTML = "Go to my lesson";
}
}
也是我這是在文件準備
function DropDown(el) {
this.dd = el;
this.initEvents();
}
DropDown.prototype = {
initEvents: function() {
var obj = this;
obj.dd.on('click', function(event) {
$(this).toggleClass('active');
event.stopPropagation();
});
}
}
$(function() {
var dd = new DropDown($('#dd'));
$(document).click(function() {
// all dropdowns
$('.wrapper-dropdown-3').removeClass('active');
});
});
在我的身體中執行的另一個jQuery函數我有這個
<body onload="CheckCookie()">
<div id="dd" class="wrapper-dropdown-3">LoGG
<ul class="dropdown">
<li><a href="#" id="firstlink">Gismo Account</a> </li>
</div>
</body>
一切工作爲我想要但是當我添加
改變DD DIV的innerHTML它給了我一個異常
SCRIPT5007:無法設置的未定義或空引用
你什麼時候執行該代碼? –
爲什麼混合不同風格的事件處理(body onload與jQuery就緒)?這很容易導致問題 - 以同樣的方式觸發您的第一個腳本。 – CBroe
由於您替換了dd的內容,因此您再也沒有「firstlink」 - 這會導致錯誤 –