我想检查一下<a>
标签的“href”是否为空,如果这是真的,它应该提示类似“网站不可用atm” ,如果链接是正确的,它应该什么也不做。检查href是否为undefined,如果是true alert smth(没有jQuery)
HTML
<a onclick="testif();" class="link" href="www.google.com">This Link is defined</a>
<a onclick="testif();" class="link" href="">This Link is undefined</a>
的JavaScript
function testif(){
if (document.getElementsByClassName("link").getAttribute("href") == ""){
Alert("Site isn't available")
}else {
// if the link is correct, alert nothing
}
};
谢谢:)
您的问题是什么? –