JQuery this 和 $(this) 的区别
来源:互联网 发布:日本二战海军知乎 编辑:程序博客网 时间:2024/05/22 00:32
简介:这是JQuery this 和 $(this) 的区别的详细页面,介绍了和jquery,有关的知识,加入收藏请按键盘ctrl+D,谢谢大家的观看!要查看更多有关信息,请点击此处
What is "this"?
In many object-oriented programming languages, this (or self) is a keyword which can be used in instance methods to refer to the object on which the currently executing method has been invoked.
复制代码 代码如下:
$("#textbox").hover(
function() {
this.title = "Test";
},
fucntion() {
this.title = "OK”;
}
);
这里的this其实是一个Html 元素(textbox),textbox有text属性,所以这样写是完全没有什么问题的。
但是如果将this换成$(this)就不是那回事了,Error–报了。
Error Code:
复制代码 代码如下:
$("#textbox").hover(
function() {
$(this).title = "Test";
},
function() {
$(this).title = "OK";
}
);
这里的$(this)是一个JQuery对象,而jQuery对象沒有title 属性,因此这样写是错误的。
JQuery拥有attr()方法可以get/set DOM对象的属性,所以正确的写法应该是这样:
正确的代码:
复制代码 代码如下:
$("#textbox").hover(
function() {
$(this).attr('title', ‘Test');
},
function() {
$(this).attr('title', ‘OK');
}
);
使用JQuery的好处是它包裝了各种浏览器版本对DOM对象的操作,因此统一使用$(this)而不再用this应该是比较不错的选择。
jQuery一步一步实现跨浏览器的可编辑表格,支持IE、Firefox、Safari、Chrome、Opera
ext checkboxgroup 回填数据解决
- JQuery 中this 和 $(this) 的区别
- JQuery -- this 和 $(this) 的区别
- JQuery this 和 $(this) 的区别
- JQuery -- this 和 $(this) 的区别
- JQuery -- this 和 $(this) 的区别
- JQuery -- this 和 $(this) 的区别
- jquery里面的$(this) 和this区别
- JQuery -- this 和 $(this) 的区别
- JQuery -- this 和 $(this) 的区别
- JQuery -- this 和 $(this) 的区别
- jquery $(this)和this的区别
- JQuery -- this 和 $(this) 的区别
- jquery中$this和$(this)的区别
- jquery中this 和 $this 的区别
- JQuery -- this 和 $(this) 的区别
- JQuery中$(this)和this的区别
- JQuery -- this 和 $(this) 的区别
- JQuery -- this 和 $(this) 的区别
- json的解析方式
- Jquery Ajax学习实例7 Ajax所有过程事件分析示例
- jquery解析json
- hjpestore 设计实现系列
- jQuery 解析xml文件
- JQuery this 和 $(this) 的区别
- POJ 2263 Heavy Cargo(图的遍历)
- poj3067
- JS 面向对象的5钟写法
- javascript 面向对象编程基础:继承
- javascript 面向对象编程基础 多态
- javascript 面向对象编程基础:封装
- jquery select(列表)的操作(取值/赋值)
- JQUERY 浏览器判断实现函数