可能重复:
this.href vs $(this).attr('href')
为什么attr方法不能直接获取属性呢?难道this.href获取的不就是属性吗?href属性有什么特殊之处,它能够直接给你绝对路径吗?
this.href vs $(this).attr('href')
这是我的代码:
$(function () {
$("a.Delete").click(function () {
console.log(this.href);
console.log($(this).attr("href"));
return false;
});
and here is my link
<a class="Delete" href="/Contact/Delete/10402">Delete</a>
这是我的输出结果:
http://localhost:59485/Contact/Delete/10402
/Contact/Delete/10402
为什么attr方法不能直接获取属性呢?难道this.href获取的不就是属性吗?href属性有什么特殊之处,它能够直接给你绝对路径吗?