Visual inspection Many people do not know this, I was also, know that these two things a little different, but it is not clear, then here, I would like to say in detail
As you all know, HTML tags can be written directly in the <> angle brackets, such as
$ (' img '). attr (' src ') or $ (' img '). Prop (' src ') Yes, it doesn't make any difference.
But one thing to note is that in HTML tags you can write some wonderful properties such as then how do you get this whatyourname attribute?
Use only $ (' img '). attr (' src '), if using. Prop () is not available.
That is, . attr () can get all the properties of a DOM element, including both the self-contained and the arbitrarily added properties of the background.
. Prop () can only get the properties of the DOM element's own.
So the question is, why?
We all know that jquery is based on the native JS, then the native JS how to get a picture of the src it?
There is a picture like this
JS gets can be in two ways document.getElementById (' pic '). src or document.getelmenetbyid (' pic '). getattribute (' src ')
Compared to the present should be very clear, directly through the. Src to get the image address is. Prop () in the encapsulated JS
The getattribute (' src ') to get the image address is the. attr () Encapsulated JS
So, in comparison, the efficiency of the. Prop () method should be higher than the efficiency of. attr (), well understood, but. attr () is more powerful and covers the. Prop ().
If you don't want to run efficiently, use it all. attr () All right.
Another problem is that the values obtained by. Prop () and. attr () are slightly different on the Disable property of the button, please see this article of the half old man for details http://www.cnblogs.com/Showshare/p/ Different-between-attr-and-prop.html
If you have any problems or mistakes, please contact me first.
About interviewing the difference between. attr () and. Prop () in jquery