从射击时的OnClientClick是假的onclick停止? [英] Stopping onclick from firing when onclientclick is false?

查看:133
本文介绍了从射击时的OnClientClick是假的onclick停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用一个按钮的OnClientClick 属性做了客户方的检查。如果检查返回真正,然后火的onclick 事件。如果客户方检查返回,不火的的onclick 事件。

Is it possible to use the onclientclick property of a button to do a clientside check. If the check returns true, then fire the onclick event. If the clientside check returns false, don't fire the onclick event.

这可能吗?

更新:

2,这些工作:

Stops the form from submitting:
OnClientClick="return false;"


Allows the form to submit:
OnClientClick="return true;"


接下来的2不工作:


The next 2 do not work:

// in js script tag
function mycheck() {
    return false;
}

// in asp:button tag
OnClientClick="return mycheck();"


// in js script tag
function mycheck() {
    return true;
}

// in asp:button tag
OnClientClick="return mycheck();"

据提交表单两次。

It submits the form both times.

这是为什么?

推荐答案

您要添加收益里面的OnClientClick一个函数被调用后。否则,该按钮会回来后即使函数返回false。

You want to add return inside OnClientClick after a function is called. Otherwise, the button will post back even if function returns false.

<asp:button ID="Button1" runat="server" OnClick="Button1_Click" 
    OnClientClick="return checkValidation()" Text="Submit" />

<script type="text/javascript">
    function checkValidation() {
        return confirm('Everything ok?');
    }
</script>

这篇关于从射击时的OnClientClick是假的onclick停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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