<span class="yanshidiv" style="background: #407de9;color: #fff;padding: 5px 8px;border-radius: 3px;">
<a class="yanshia" href="http://www.520ym.net" style="color:#fff;" target="_blank">点击访问</a></span>
<span class="zanwu" ><a style="color:#407de9;">暂无链接</a></span>
<script>
$(function() {
var n = 0;
$('.yanshidiv .yanshia').each(function(){
if($(this).attr('href')!=''){
n += 1;
}
});
if(n>0){
$('.yanshidiv').show();
$('.zanwu').hide();
}else{
$('.yanshidiv').hide();
$('.zanwu').show();
}
});
</script>
解释下上面js代码,如果class定义为yanshidiv下的a标签有链接时就显示,如果没有链接时就显示class为"zanwu"下的a标签内容