jQuery中this与$(this)的区别
但是如果将this换成$(this)就不是那回事了,Error--报了。this与$(this)的区别在此。
JQuery拥有attr()方法可以get/set DOM对象的属性,所以正确的写法应该是这样:
正确的代码:
jQuery中this与$(this)的区别就介绍到这里。
- $("#textbox").hover(
- function() {
- this.title = "Test";
- },
- fucntion() {
- this.title = "OK”;
- }
- );
但是如果将this换成$(this)就不是那回事了,Error--报了。this与$(this)的区别在此。
- Error Code:
- $("#textbox").hover(
- function() {
- $(this).title = "Test";
- },
- function() {
- $(this).title = "OK";
- }
- );
JQuery拥有attr()方法可以get/set DOM对象的属性,所以正确的写法应该是这样:
正确的代码:
- $("#textbox").hover(
- function() {
- $(this).attr(’title’, ‘Test’);
- },
- function() {
- $(this).attr(’title’, ‘OK’);
- }
- );
jQuery中this与$(this)的区别就介绍到这里。
转载请注明:谷谷点程序 » jQuery中this与$(this)的区别