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” - 这会导致错误 –