Day! Finally, I knew what was wrong last time? To know the differences between the jqueryprop method and the attr method, you must first understand the concepts of property and attribute: 1. We know that for the checkbox DOM object, it must have
Day! Finally, I knew what was wrong last time? To know the difference between the jquery prop method and the attr method, you must first understandConcepts of property and attribute:
1. we know that for the checkbox DOM object, it must have a selection status, and there are only two options, either selected or not selected, therefore, no matter when we use the prop method to obtain its checked value, we can get a definite value, true or false. For the HTML representation of the checkbox, it can be simply expressedHere, you do not need to assign values to the checked attribute. In this case, when you use attr to obtain the checked value, the value will be undefined.
2. For some HTML tag attributes, different attribute names will be matched in the DOM object, such
Its attribute name is class, but its property name is className.
3. If you use prop to assign values, the current State is assigned values. For some attributes, attr assigns an initial value. In this way, prop will always change the status of the checkbox dynamically. For Some browsers, attr can only change the initial status of the checked before the checkbox is displayed on the page, then, the checked status cannot be changed. In addition, the prop can always get the current status of the checkbox, regardless of the current status of the checkbox, attr can only get the initial status.
4. the built-in DOM property cannot be removed, but attribute can.
<以上四点参考资料:http: www.cnblogs.com studynote p 3475005.html>
Let's talk about it again. Difference between the prop method and the attr method:
Currently, I only encounter differences in checkbox, but IE is not compatible. The official differences are as follows:
1. Add a property name. This property will take effect. Use prop ();
2. There are true and false attributes using prop ();
3. For others, use attr ();