日期:2014-05-16 浏览次数:20478 次
<div tree="T">123</div>
<div tree="T01">123</div>
<div tree="T02">123</div>
<div tree="T0101">123</div>
<div tree="T0201">123</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
//以什么开头和tree的长度分别判断一次就可以了
//下面的是找出以T01开头的DIV tree的长度
$(function(){
$("div[tree^=T01]").each(function(){
alert($(this).attr('tree').length);
});
})
</script>
<div tree="T">123</div>
<div tree="T01">123</div>
<div tree="T02">123</div>
<div tree="T0101">123</div>
<div tree="T0201">123</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
//过滤以T01开头,tree属性长度为5位的div,
$("div").filter(function(){
return /^T01..$/.test($(this).attr("tree"));
}).css("background-color","#ff0000");
})
</script>
<div tree="T">123</div>
<div tree="T01">123</div>
<div tree="T02">123</div>
<div tree="T0101">123</div>
<div tree="T0201">123</div>