84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
$($("p").get(0)).css('background','red'); // $("p").get(0).style.color='red' 这两种方式都可以改变p的样式,但是我不知道这有什么区别呢,看了其他人的说明也不是很明白。求详细解答。
About how to use get() in dom operation? - PHP Chinese website Q&A - About how to use get() in dom operation? - PHP Chinese website Q&A
Take a look around and learn.
get是用于转换dom对象var s = $("p").get(0); 把jquery对象转换成dom对象var s=$($("p").get(0)); 把jquery对象转换成dom对象后 再把它转化成jquery对象所以你的$("p").get(0).style.color='red' 才可以成功 因为在js中 dom操作 改变样式就是用.style.color这种形式而在jquery中 改变样式 用.css("color","")这种形式所以你的$($("p").get(0)).css('background','red');才可以成功
About how to use get() in dom operation? - PHP Chinese website Q&A - About how to use get() in dom operation? - PHP Chinese website Q&A
Take a look around and learn.
get是用于转换dom对象
var s = $("p").get(0); 把jquery对象转换成dom对象
var s=$($("p").get(0)); 把jquery对象转换成dom对象后 再把它转化成jquery对象
所以你的$("p").get(0).style.color='red' 才可以成功
因为在js中 dom操作 改变样式就是用.style.color这种形式
而在jquery中 改变样式 用.css("color","")这种形式
所以你的$($("p").get(0)).css('background','red');才可以成功