this是html元素,$(this)是变量名。$(this)=jquery(this)顾返回的是一个jQ对象。
this是dom对象不可以直接使用jQ中的方法,通过$(this)转换为jQ对象就可以使用jQ中的方法了。
如下:this使用siblings()时会报错,而转为$(this)就可以使用该方法了。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>this和$(this)</title>
</head>
<body>
<div>
<input type="text" value="1">
<button id="btn">按钮</button>
</div>
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$("#btn").click(function(){
alert(this);//[object HTMLButtonElement]
alert($(this));//[object Object]
<html lang="en">
<head>
<meta charset="UTF-8">
<title>this和$(this)</title>
</head>
<body>
<div>
<input type="text" value="1">
<button id="btn">按钮</button>
</div>
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$("#btn").click(function(){
alert(this);//[object HTMLButtonElement]
alert($(this));//[object Object]
console.log(this.siblings());//报错:this.siblings is not a function
console.log($(this).siblings());//[input, prevObject: init(1), context: button#btn]
})
</script>
</body>
</html>
console.log($(this).siblings());//[input, prevObject: init(1), context: button#btn]
})
</script>
</body>
</html>