条件onclick jQuery [英] Condition onclick jquery

查看:92
本文介绍了条件onclick jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实有一个带有某种条件的href.如果不遵守这些条件,我可以阻止href吗?如果所有条件都得到遵守,我希望href运行...

I have an href indeed an onclick with some condition. Can I block an href if these conditions is not respected ? If the all conditions is respected, I want that the href run...

<a class="btn btn-small" href="page2.php" onclick="verification()">Valid</a>

jquery中的条件如下:

Here the conditions in jquery it's like that :

function verification()
{
    var player = 10;
    if(player <= 10)
    {
      alert('OK');
    }
    else
    {
      alert('NO');

    }
}

非常感谢您

推荐答案

由于您已使用Jquery标记了此问题,因此建议您在这种情况下使用e.preventDefault().

Since you have tagged this question with Jquery, I would suggest you to use e.preventDefault() in this occassion.

HTML:

<a class="btn btn-small" href="page2.php">Valid</a>

JQUERY:

$('a.btn').click(function(e){
 //I just assumed that you would add some real conditions over here. 
 if(!condition){ e.preventDefault(); }
});

这篇关于条件onclick jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆