<head>
<script src="jquery/jquery.js" type=text/javascript></script>
<script>
$(document).ready(
function(){
if($("h1").length >0)
{
alert("有")
}
else
{
alert("没有")
}
}
)
</script>
</head>
<body>
<h1>dddddddddddddd</h1>
</body>
</html>
可以简单的判断任何标签
使用attr()方法来实现我们可以使用attr()来设置属性,比如设置为只读:
$("#id").attr("disabled",true)
反之,可以通过获取属性值来判断指定属性是否存在
if(typeof($("#id").attr("rel"))=="undefined") {
//不存在执行
}else{
//存在执行
}
获取节点标签,例如:var node=document.getElementById('nice')获取其属性节点:var cls=node.getAttribute('className')//如果是空字符串,说明不存在。
即 cls.length==0