最近我遇到了一個問題。我想在我的博客模板中添加此代碼。我已經給它取代'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 {}中, –