A. Assignment of time
If <input type = "checkbox" checked> This attribute names can only take effect properties
Recommended prop, namely: $ ( 'input') prop ( 'checked', true);.
Meanwhile, to false indicates canceled, namely: $ ( 'input') prop ( 'checked', false);.
Of course, also attr line: $ ( 'input') attr ( 'checked', 'what is written here will do');.
Cancel property is removed: $ ( 'input') removeAttr ( 'checked');.
II. The value of time
如果是<input id="input1" type="checkbox" checked><input id="input2" type="checkbox">
Recommended prop, namely:
$('#input1').prop('checked'); //返回true
$ ( '# Input2') prop ( 'checked');. // returns false
The use attr, then:
$('#input1').attr('checked'); //返回checked
$('#input2').attr('checked'); //返回undefined
III. Special attribute value assignment
For example a data-tips require additional input of the attribute. Become like <input type = "text" value = "" data-tips = "aa">
At this time only write: $ ( 'input') attr ( 'data-tips', 'aa');.
Use prop is no good.
But reading time, both possible:
$ ( 'Input') attr ( 'data-tips');. // return aa
$ ( 'Input') prop ( 'data-tips');. // return aa
Use the scope attribute
prop used in multi-selected and checked attributes