JQuery 中this和$(this)获取对象操作DOM对象的元素属性

Posted shiyongzhe88

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JQuery 中this和$(this)获取对象操作DOM对象的元素属性相关的知识,希望对你有一定的参考价值。

$(‘.button‘).click(function () {
var active = $(‘.buttons-tab a‘).children(‘input‘).attr(‘value‘)
alert($(this).attr(‘id‘))
alert(this)
})
//可以看出来$(this)是jquery对象,而this是DOM对象:!!!!!!!!!!!!!!!!!!!!!!!!!!
alert($(this)); 弹出的结果是[object Object ]
alert(this); 弹出来的是[object htmlImageElement]


如何获取$(this)子对象?=========> find()
$(this).attr(‘id‘)


转自 https://blog.csdn.net/haoaiqian/article/details/62882594













以上是关于JQuery 中this和$(this)获取对象操作DOM对象的元素属性的主要内容,如果未能解决你的问题,请参考以下文章