jQuery中this与$(this)的区别
2015-08-30 07:55
603 查看
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link href="style/css.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.7.2.min.js"></script> <script> $(document).ready(function(){ console.log("ready"); $("#textbox").hover( function(){ console.log("fdsfds"); this.title="Test"; }, function(){ this.title="OK"; } ); }); </script> </head> <body> <p id="textbox">pppppppppppp</p> </body> </html>
这里的this其实是一个Html 元素(textbox),textbox有title属性,所以这样写是完全没有什么问题的。
但是如果将this换成$(this)就不是那回事了,Error--报了。$(this)表示一个jquery对象。this与$(this)的区别在此。
要用$(this),得这样写。
$("#textbox").hover( function() { $(this).attr(’title’, ‘Test’); }, function() { $(this).attr(’title’, ‘OK’); } );
一个移动设备触控滑块的js很不错的样子:
http://www.swiper.com.cn/
相关文章推荐
- jQuery div层渐入渐出效果
- jQueryMobile的组件之列表(listview)
- jQuery鼠标事件汇总
- IE8下jQuery改变png图片透明度时出现的黑边
- jquery.mousewheel实现整屏翻屏效果
- jQueryMobile的组件之栅格系统(grid)
- jQuery中的事件和动画
- jQuery File Upload
- JS添加节点方法与JQuery添加节点方法的比较及总结
- Jquery对象,DOM对象
- JQuery选择器
- JQuery 自动触发事件
- jquery模拟下拉框单选框复选Select,Checkbox,Radio
- jQuery图片特效脚本prettyPhoto简介
- jquery 中 live事件委派 与 bind事件绑定
- Javascript、Jquery获取浏览器和屏幕各种高度宽度
- jquery专业的导航菜单特效代码分享
- 利用jquery完成表单域的收集,利用ajax实现信息传递给服务器存储
- Spring mvc+jackson+jquery 返回json数据出现整合出现包冲突问题
- jquery中 val()操作 与 复选框、下拉列表、单选按钮的设置