jquery - this.id 与 $(this).attr ('id' )

标签 jquery

$(this).attr('id') 

与:

相同
this.id

最佳答案

不,它们并不完全相同。

它们都会返回元素的 ID,但如果元素没有 ID,则 this.id 将返回空字符串,而 $(this).attr("id") 将返回未定义

关于jquery - this.id 与 $(this).attr ('id' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5597317/

相关文章:

javascript - 如何使用最小和最大属性添加和减去输入值。查询

javascript - 将 Bootstrap 工具提示与 SVG 对象一起使用 - 尽管指定了容器但不显示

javascript - 使用列表中所选选项的值设置 div 类

jquery - 为什么jquery的ui.css文件的字体大小比正常的大?

javascript - 动画之前等待图像重新加载

javascript - Jquery 图片库下一个/上一个图像按钮

javascript - 如何用 table 制作 Accordion

jquery - 你如何解释 jQuery(document).ready()?

javascript - jQuery Mobile : $. 移动未定义

javascript - 使用iCheck-helper时如何处理radio事件?