<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!-- 基本选择器 -->
<!--id选择器-->
<div id="notMe"><p> id="notMe"</p></div>
<div id="myDiv">id="myDiv"</div>
<script type="text/javascript">
$("#myDiv")
</script>
<!-- 结果<div id="myDiv">id="myDiv"</div> -->
<!--element选择器-->
<div>DIV1</div>
<div>DIV2</div>
<span>SPAN</span>
<script type="text/javascript">
$("div");
</script>
<!-- 结果 <div>DIV1</div>, <div>DIV2</div> -->
<!--class选择器-->
<div class="notMe">div class="notMe"</div>
<div class="myClass">div class="myClass"</div>
<span class="myClass">span class="myClass"</span>
<script type="text/javascript">
$(".myClass");
</script>
<!--结果 <div class="myClass">div class="myClass"</div>, <span class="myClass">span class="myClass"</span>-->
<!--"*"选择器-->
<div>DIV</div>
<span>SPAN</span>
<p>P</p>
<script type="text/javascript">
$("*")
</script>
<!--结果<div>DIV</div>, <span>SPAN</span>, <p>P</p> -->
<!--selector1,selector2,selectorN选择器-->
<div>div</div>
<p class="myClass">p class="myClass"</p>
<span>span</span>
<p class="notMyClass">p class="notMyClass"</p>
<script type="text/javascript">
$("div,span,p.myClass")
</script>
<!--结果 <div>div</div>, <p class="myClass">p class="myClass"</p>, <span>span</span>-->
</body>
</html>
js基本选择器 硬货!!
最新推荐文章于 2022-03-14 16:38:41 发布