问题
If I want to change the href of a link dynamically, should I do so using prop() or attr()?
回答1:
You would use .attr(), as .prop() is more commonly used for boolean properties such as checked, selected, etc - though it is certainly possible with .prop it's arguably less clear as per your intent
Though I do believe that ultimately they are very similar (or used to be) functionality-wise
Just a note: the jQuery API site seems to follow the boolean 'sway':
.prop() - Examples use checked and disabled
.attr() - Examples use alt title and src
来源:https://stackoverflow.com/questions/18189858/should-href-be-set-with-prop-or-attr