20170420 problems and solutions-1. About how to use jquery to add and remove the label checked attribute whose type is radio in input, jquerychecked
Requirement: remove the checked attribute of radio and then reset it;
Preliminary scheme:
$("auForm input :radio[value='0']").removeAttr('checked');$("auForm input :radio[value='1']").removeAttr('checked');if(l.isover==0) $("auForm input :radio[value='0']").attr('checked','true');if(l.isover==1) $("auForm input :radio[value='1']").attr('checked','true');
Actual Problem: When removeAttr () is used to remove the radio checked attribute, adding it again using attr () does not work;
Solution:
$("#auForm input:radio[value='1']").removeAttr('checked');$("#auForm input:radio[value='0']").removeAttr('checked'); if(l.isover==1) $("#auForm input:radio[value='1']").prop('checked','true');if(l.isover==0) $("#auForm input:radio[value='0']").prop('checked','true');
You can use prop () to reconfigure this attribute;
For this reason, I checked the usage of attr () and prop () in jquery:
A Method prop () has been added since jQuery 1.6, because before jQuery 1.6, the use of attr () sometimes produces inconsistent behavior.
According to official suggestions:Properties with both true and false attributes, such as checked, selected, or disabled using prop (), others using attr (),
For more information, see this blog: http://wenzhixin.net.cn/2013/05/24/jquery_attr_prop.