this.id与$(this).attr('id') [英] this.id vs. $(this).attr('id')

查看:562
本文介绍了this.id与$(this).attr('id')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(this).attr('id') 

与以下相同:

this.id

推荐答案

不,它们并不完全相同.

No, they're not exactly the same.

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

They'll both return the element's ID, but if the element has no ID, then this.id will return a blank string while $(this).attr("id") will return undefined.

这篇关于this.id与$(this).attr('id')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆