jquery教程9:jQuery中this选择器用法
6、this选择器用法
$(this) 表示当前 HTML 元素,在使用时要注册在不同的环境中,它表示的意义会有一定的区别。另外也要注意$(this)和this的意义也是不同的。
例如:$(document).ready(function(){
$("#b1").click(function(){
$(this).css("background-color","#ffff00");
//此处的this表示的是#b1元素
});
$("#b2").click(function(){
$("p").css("color","#ff0000");
$(this).css("background-color","#00ff00");
//此处的this表示的是#b2元素,
});
});
![]() |
豫公网安备 41010202002486号 | ICP备案:豫ICP备18044432号-1 |