基本选择器示例:
改变颜色:
改变id为one的元素的背景色 $('#one')
.css("background","#bbffaa");
<p class="xxxx">22222</p>
<p class="yyyy">22222</p>
<p id="one">scan</p>
<p class="myClass">33333</p>
<p class="zzzz">4444</p>
<script type="text/javascript" src="jquery-2.2.2.min.js"></script>
<script type="text/javascript" src="a23.js"></script>
node2:/var/www/html#cat a23.js
var $aa=$("#one");
console.log($aa);
导航至 http://192.168.137.3/a23.html
Object { 0: p#one, length: 1, context: HTMLDocument http://192.168.137.3/a23.html, selector: "#one" }
a23.js:2:1
忽略了对含 [LenientThis] 的属性进行获取或设置,因为“this”对象不正确。
a23.html
改变class为mini的所有元素的背景色
$('.mini')
.css("background","#bbffaa");
node2:/var/www/html#cat a23.html
<p class="xxxx">22222</p>
<p class="yyyy">22222</p>
<p id="one">scan</p>
<p class=mini>33333</p>
<p class="zzzz">4444</p>
<script type="text/javascript" src="jquery-2.2.2.min.js"></script>
<script type="text/javascript" src="a23.js"></script>
node2:/var/www/html#cat a23.js
$("#one")
.css("background","#bbffaa");
$('.mini')
.css("background","#bbffaa");
改变元素名是<div>的所有元素的背景色
$('div')
.css("background","#4384ba");
node2:/var/www/html#cat a23.html
<p class="xxxx">22222</p>
<p class="yyyy">22222</p>
<p id="one">scan</p>
<p class=mini>33333</p>
<div class=mini>赵杨健</div>
<p class="zzzz">4444</p>
<script type="text/javascript" src="jquery-2.2.2.min.js"></script>
<script type="text/javascript" src="a23.js"></script>
node2:/var/www/html#
node2:/var/www/html#cat a23.js
$("#one")
.css("background","#bbffaa");
$('.mini')
.css("background","#eeeeeeee");
$('div')
.css("background","#4384ba");