简体   繁体   English

JQuery使用单击元素的href侦听单击和警报

[英]JQuery listen to click and alert with clicked element's href

The title is pretty self explanatory. 标题非常自我解释。

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

How do I replace 'href' with the clicked element's href? 如何用点击元素的href替换'href'?

Like this: 像这样:

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

Try this: 尝试这个:

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

Or 要么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM