0
假設我在最後一個div後有下列下拉菜單,點擊後會出現一個下拉菜單。Javascript和href
<div id="test"> <a href="clickthrough.php">Arrow</a> </div>
我希望用戶能夠點擊這個元素,並且下拉出現,但也如果他點擊月中能夠直接在新標籤中打開此鏈接。換句話說,我想阻止默認操作onclick,但仍然顯示懸停或任何其他元素的鏈接。
謝謝
假設我在最後一個div後有下列下拉菜單,點擊後會出現一個下拉菜單。Javascript和href
<div id="test"> <a href="clickthrough.php">Arrow</a> </div>
我希望用戶能夠點擊這個元素,並且下拉出現,但也如果他點擊月中能夠直接在新標籤中打開此鏈接。換句話說,我想阻止默認操作onclick,但仍然顯示懸停或任何其他元素的鏈接。
謝謝
你可以做
<div id="test"> <a href="clickthrough.php" onclick="FunctionForOpeningLink();return false;">Arrow</a> </div>
與jQuery 1.7+
$('#test a').on('click', function (e) {
if (e.which < 2) { // left mouse button
e.preventDefault();
// and code to show dropdown
}
});
將URL傳遞給函數,並返回一個適當的值:'...的onclick =「返回FunctionForOpeningLink(this.href);」 ...'然後有* FunctionForOpeningLink *如果它很高興返回false,如果沒有返回undefined並且鏈接將被跟隨。 – RobG