[英]JQuery listen to click and alert with clicked element's href
標題非常自我解釋。
$(".js").click(function (e) {
alert('this elements href is: ' + href);
});
如何用點擊元素的href替換'href'?
像這樣:
$(".js").click(function (e) {
alert('this elements href is: ' + $(this).attr('href'));
}
嘗試這個:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.