JQuery基本選取器
選取器
描述
返回
#id
根據給定的id匹配一個元素
單個元素
.class
根據給定的類名匹配元素
集合元素
element
根據給定的元素名匹配元素
集合元素
*
匹配所有元素
集合元素
Selector1,selector2,...
將每一個選取器匹配到的元素合并後一起返回
集合元素
例子:
[javascript]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript" src="jquery-core/jquery-1.8.0.js"></script>
<script type="text/javascript">
$(function(){
$('#bt1').click(function(){
alert('id選取器:'+$('#d1').html()
+"\nclass選取器:"+$('.c1').html()
+"\n元素選取器:"+$('p').eq(0).html()
+"\n*選取器:"+$('*').eq(5).html()
+"\n多選取器選中的個數:"+$('div,p,#bt1').length
);
});
});
</script>
</head>
<body>
<div id="d1">我是一個div</div>
<div class="c1">我是一個div2</div>
<p>我是一個p</p>
<input type="button" value="button" id="bt1" />
</body>
</html>