JQuery监听点击事件并弹出所点击元素的href。

3
标题已经很明显了。
$(".js").click(function (e) {
        alert('this elements href is: ' + href);
    });

如何用被点击元素的href替换“href”?

2个回答

6

像这样:

$(".js").click(function (e) {
    alert('this elements href is: ' + $(this).attr('href'));
}

3

试试这个:

alert('this elements href is: ' + this.href);//best one

或者

alert('this elements href is: ' + $(this).attr("href"));//but it is unnecessary to wrap an object into another object

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接