admin管理员组文章数量:1418667
I have a link in the html page and it has the id="redirect"
and this in (script.js)
window.onload = initAll();
function initAll(){
document.getElementById("redirect").onclick = clickHandler;
}
function clickHandler(){
alert("Sure!");
return true;
}
I'm getting this error message
SCRIPT5007: Unable to set value of the property 'onclick': object is null or undefined
I tried this in (IE9,IE8,chrome,Firefox 4.0.1) and still not running, please help
I have a link in the html page and it has the id="redirect"
and this in (script.js)
window.onload = initAll();
function initAll(){
document.getElementById("redirect").onclick = clickHandler;
}
function clickHandler(){
alert("Sure!");
return true;
}
I'm getting this error message
SCRIPT5007: Unable to set value of the property 'onclick': object is null or undefined
I tried this in (IE9,IE8,chrome,Firefox 4.0.1) and still not running, please help
Share Improve this question edited Jun 14, 2011 at 10:59 DanielB 20.2k2 gold badges46 silver badges52 bronze badges asked Jun 14, 2011 at 10:53 JohnJohn 331 silver badge3 bronze badges1 Answer
Reset to default 4You have to write:
window.onload = initAll;
At the point of execution the document element does not exists, because you don't call the function on load. You call the initAll()
and assigning its return value to window.onload
which is undefined or raising the error.
本文标签: javascripthelp with error SCRIPT5007 Unable to set value of the property 39onclick39Stack Overflow
版权声明:本文标题:javascript - help with error SCRIPT5007: Unable to set value of the property 'onclick' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745294817a2652011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论