1. 程式人生 > 其它 >2.jQuery基礎選擇器

2.jQuery基礎選擇器

<head>
<meta charset="UTF-8">
<title>1.基礎選擇器</title>
</head>
<body>
<div id="web">百度</div>
<div class="info">今日頭條1</div>
<div class="info">今日頭條2</div>
<div class="info">今日頭條3</div>
<hr>
<input type="button" value="標籤" onclick="showTag()">
<input type="button" value="class" onclick="showInfo()">
<input type="button" value="id" onclick="showid()">
<hr>
<div id="show"></div>

</body>
<script src="js/jquery-1.8.3.js"></script>
<script>
/*基礎選擇器,獲取id*/
function showid() {
//獲取id
var $id = $("#web")[0];
$("#show").html($("#web").html())
}
/*基礎選擇器,獲取class*/
function showInfo() {
//獲取class陣列
var $info = $(".info");
document.getElementById("show").innerHTML="共有info"+$info.length+"個";
}
/*基礎選擇器,獲取did標籤*/
function showTag() {
//獲取標籤陣列
var $div = $("div");

document.getElementById("show").innerHTML="共有div"+$div.length+"個";

}
</script>