原来js中的this这么好用
例如
代码
$(document).ready(function(){
var DragElement=null;
$("#zz").mousedown(function(){
DragElement=this;//这时this指的就是$("#zz")对象
$(document).mousemove(function(){
如果直接$(this).css("left")//由于是在mousemove内,这样this对象就不是$("#zz"),
这时可以用$(DragElement).css("left")//这样取的就是$("#zz")
})
})
})
var DragElement=null;
$("#zz").mousedown(function(){
DragElement=this;//这时this指的就是$("#zz")对象
$(document).mousemove(function(){
如果直接$(this).css("left")//由于是在mousemove内,这样this对象就不是$("#zz"),
这时可以用$(DragElement).css("left")//这样取的就是$("#zz")
})
})
})
真是太好用了!
作者:蓝丶 sky
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。