如何防止在单击时调用锚标记操作

时间:2014-08-21 10:05:56

标签: javascript jquery html

您好我正在通过s:url调用一个动作,并且该动作被调用形成一个锚点链接点击这样

<div  class ="QuickLink"><ul><li>
<s:url namespace="/np" action="actionName1" var="URL_ID_ONE" />
<a id="theLink1"  href="%{URL_ID_ONE}" targets="RIGHT_PANEL">Click One</a></li><li>
<s:url namespace="/np" action="actionName2" var="URL_ID_TWO" />
<a id="theLink2"  href="%{URL_ID_TWO}" targets="RIGHT_PANEL">Click Two</a></li></ul></div>

点击锚链接我需要的是什么。我会检查一个条件,如果它返回false,那么我需要停止调用通过href

调用的动作

尝试使用event.preventDefault()event.stopImmediatePropagation()进行锚点击事件 不使用jquery doc。中定义的任何事件停止函数。

3 个答案:

答案 0 :(得分:2)

$('#theLink').click(function(e) {
  e.preventDefault();
});

您需要引用来自.click()

的事件

<强>更新

您只是有条件地取消事件(它在if语句中),将取消放在函数顶部

$(document).on('click','#theLink',function(e){ 
    e.preventDefault();
     var getStat= $('#MARK_REVIEWED_BUTTON'); 
    if (getStat.attr('disabled') !='disabled'){ 
    $('#MARK_REVIEWED_BUTTON').pulsate({glow:false,color:'#D00'}); 
    } 
});

答案 1 :(得分:0)

    <script type="text/javascript">
    $("selector").click(function(event){
    event.preventDefault();
   });
    </script>

尝试在函数内使用事件,例如功能(事件)

答案 2 :(得分:0)

回调应返回false以防止href操作:

$('#someid').bind('click',function(){alert('hello'); return false;})

在这里提出并回答:https://stackoverflow.com/questions/5222466/how-to-stop-href-going-anywhere

相关问题