欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

jQuery .attr(checked)得undefined 问题解决

发布时间:2025/7/25 编程问答 45 豆豆
生活随笔 收集整理的这篇文章主要介绍了 jQuery .attr(checked)得undefined 问题解决 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

出现此错误是因为JQuery版本升级的问题。所以此处应该使用.prop();

那么,什么时候使用attr(),什么时候使用prop()?
1.添加属性名称该属性就会生效应该使用prop();
2.是有true,false两个属性使用prop();
3.其他则使用attr();
项目中jquery升级的时候大家要注意这点!

以下是官方建议attr(),prop()的使用:

 

Attribute/Property.attr().prop()
accesskey 
align 
async
autofocus
checked
class 
contenteditable 
draggable 
href 
id 
label 
location ( i.e. window.location )
multiple
readOnly
rel 
selected
src 
tabindex 
title 
type 
width ( if needed over .width() ) 

转载于:https://www.cnblogs.com/pocn/p/5314084.html

总结

以上是生活随笔为你收集整理的jQuery .attr(checked)得undefined 问题解决的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。