![](/img/trans.png)
[英]How to convert a specific onclick popup link to direct link href with tampermonkey?
[英]Detect specific link clicked with href and onclick=“setLocation()”
我正在嘗試檢測JS
是否單擊了鏈接。 這是我的代碼:
<div onclick="setLocation('http://domain.com/test')" class="gd-details" id="detail-box2">
<h2 class="gd-product-name">
<a title="test" href="http://domain.com/test">content 1</a>
</h2>
</div>
我也在嘗試使用此代碼,但它不起作用:
$(document).on("click", "a", function() { var href = $(this).attr("href"); if(href == 'http://domain.com/test'){ alert('clicked'); } else { alert('not clicked'); } });
如何檢測是否單擊了特定鏈接?
將事件處理程序添加到div click並將onclick
屬性與您的測試URL進行比較。
$(document).on("click", "div", function() {
var href = $(this).attr("onclick");
if(href === "setLocation('http://domain.com/test')"){
alert('clicked');
} else {
alert('not clicked');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.