最近我遇到了一个问题。我想在我的博客模板中添加此代码。我已经给它取代'display:none; css'选项,用我的主页功能替换信用网址。但if (footer === null) {window.location = 'http://google.com';}
不起作用。为什么?有什么问题吗?如果他们删除id='mycreditlink'
属性,我想让客户端博客重定向。我想在没有jQuery的情况下做到这一点。如何给它检查div id功能?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function creditprotection(){
var url = ('http://grplusbd.net');
var style = ('display: inline; visibility: true;');
var footer = document.getElementById('mycreditlink');
footer.href= url;
footer.style = style;
if (footer === null) {
window.location = 'http://google.com';
}
}
window.onload = function(){creditprotection();};
</script>
</head>
<body>
Powered By <a href='http://google.com' id='mycreditlink'> My Site </a>
</body>
</html>
这是不可能永远到达那里。如果'footer === null'为true,那么代码已经崩溃,因为它不能在空引用上设置'href'或'style'。 –
感谢您的帮助,现在它正在工作......我已经放置了footer.href = url;和footer.style = style;在if(footer === null)之后的else {}中, –