日期:2014-05-16 浏览次数:20340 次
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("a.[href='aaa']").each(function(){
alert($(this).text());
});
});
});
</script>
</head>
<body>
<a href="aaa">123</a>
<a href="aaa">123</a>
<label href="aaa">444</label>
<a>123</a>
<button type="button">Click me</button>
</body>
</html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
$("button").click(function(){
$("a[href='aaa']").each(function(){
alert($(this).text());
});
});
$("#abv").click(function(){
$("a").each(function(){
alert($(this).text());
});
});
$("#abc").click(function(){
$("label").each(function(){
alert($(this).text());
});
});
});
</script>
</head>
<body>
<a href="aaa">123</a>
<a href="aaa">234</a>
<label href="aaa">345</label>
<a>456</a>
<input type="button" value="遍历a标签" id="abv"/>
<input type="button" value="遍历label标签" id="abc"/>
<button type="button">遍历a下aaa标签</button>
</body>
</html>