我尝试添加console.log,但我无法弄清楚。
$(this).href
这不是指最终链接位置吗?
就像如果
<a href="test.php">here</a>
我们现在所在的页面是 test.com $(this).href 是否为我们提供“test.php”或 test.com/test.php?我需要访问两者中的后者。
有什么建议吗?
最佳答案
$(this)
是一个 jQuery 对象,不具有 href
属性。
您应该使用 $(this).attr('href')
或 this.href
。
不同之处在于$(this).attr('href')
返回'test.php'
,
并且 this.href
返回 'http(s?)://test.com/test.php'
关于javascript - Jquery 和 object href 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16247210/