JavaScript中的this指的是什么呢?
this指的就是当前标签本身,比如某个按钮的onclick的处理函数中需要识别是哪个按钮触发的,这个时候就需要这样做:
<script>
function test(wh){
alert($(wh).attr("id"));
console.log(wh.id)//JavaScript写法
console.log($(wh).attr("id"))//jQuery写法
}
</script>
<html>
<body>
<button id="13" onclick="test(this)" name="btn" />
</body>
</html>
而$(this)就是jQuery中对this的包装,然后$(this)就可以用jQuery对象的方法了
注意:
如果需要将this传进去ajax中,则不能用ajax,而需要将this赋值给一个变量,再将变量在ajax中使用