jQuery replacing relative links

后端 未结 6 1262
忘掉有多难
忘掉有多难 2020-12-19 17:33

Hopefully someone can explain some odd behavior I\'ve encountered with jQuery. The following script is looking for relative links on my page and replacing them with absolut

6条回答
  •  再見小時候
    2020-12-19 17:46

    .prop() grabs the property value as opposed to the attribute value. While similar, there are some subtle, important differences -- one of which applies here. The href property on an element is always the full path. For example:

    
    
    
    

    In other words, you're appending the domain to a value that is already an absolute path. Just use .attr() rather than .prop() and you'll be fine.

    To see an example, open your console and go to this page: http://jsfiddle.net/JUcHU/

提交回复
热议问题