input radio attr动态赋值问题

程序环境:easyui+jQuery

代码



最近发现用$("input[name='Fruit'][value='西瓜']").attr("checked",true);动态赋值没有赋值成功。原来以为是easyui的问题,后来查考文档才发现jQuery中使用prop可以完美解决这个问题。
$("input[name='Fruit'][value='西瓜']").prop("checked",true);

那么,什么时候使用attr,什么时候使用prop?

1.添加属性名称该属性就会生效应该使用prop.
2.是有true,false两个属性使用prop.
3.其他则使用attr

你可能感兴趣的:(input radio attr动态赋值问题)