检测用href点击的特定链接和onclick =" setLocation()"

时间:2016-01-14 18:38:39

标签: javascript jquery

我正在尝试检测是否点击了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>

我也尝试使用此代码,但它不起作用:

&#13;
&#13;
	$(document).on("click", "a", function() {
	var href = $(this).attr("href");
		if(href == 'http://domain.com/test'){
			alert('clicked');
		} else { 
			alert('not clicked');
		}
	});
&#13;
&#13;
&#13;

如何检测是否点击了特定链接?

1 个答案:

答案 0 :(得分:1)

为div点击添加一个事件处理程序,并将 $(document).on("click", "div", function() { var href = $(this).attr("onclick"); if(href === "setLocation('http://domain.com/test')"){ alert('clicked'); } else { alert('not clicked'); } }); 属性与您的测试网址进行比较。

public static class yummy
{
    public static FAKER()
    {
       throw new exception();
    }
}
相关问题