如何停止javascript中单击按钮的回发 [英] how to stop postback on button click in javascript

查看:63
本文介绍了如何停止javascript中单击按钮的回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数字键盘,每当我按下任何按钮时,它都会将页面发回,所以我该如何停止呢?谁能帮我....如果可以的话,发给我代码.

I have a num pad,whenever I press any button it post back the page so how could I stop this ?? can anyone help me please ....send me code if you could so.

推荐答案

在aspx代码上,为相关按钮写
On the aspx code, for the concerned button write
OnClientClick="return false;"


这将停止回发页面.如果您需要执行某些函数调用(如验证等),也可以执行此操作.


This will stop posting back the page. If you need to do some function call, like validation etc, you can do that too.

OnClientClick="MyFunction(); return false;"


定义一个将值存储在某些变量中的函数


Define a function which stores value in some variable

MyFunction()
{
myVariable = myVariable + "number you got from button";
return false;
}


如果您需要有条件地停止回发,则可以这样写:


If you need to do conditional stopping of postback you can write like

OnClientClick="MyFunction();"


并定义功能,如


And define function like

function MyFunction() 
{
if (condition == true)
return false;
else
return true;
}


在这种情况下,如果条件为true,则不会回发,否则会回发.

希望能有所帮助.如果是这样,请将其标记为解决方案/upvote.

谢谢
Milind


In this case, if condition is true, it will NOT post back else it will post back.

Hope that helps. If it does, mark it as solution/upvote.

Thanks
Milind


希望它会帮助您


Hope it''ll help u


<asp:button id="btnID" runat="server" text="Click Me" onclientclick="return false;"  />




根据我的理解,如果您的要求是停止不被调用的ASP按钮单击事件,那么您可以在按钮的Onclientclick上使用return false.

Hi,

As per my understanding, if your requirement is to stop the asp button click event not to be called, then you can use return false on your Onclientclick of the button.

<asp:button runat="server" ...="" onclientclick="return false"  />



让我知道我的理解是否错误.



Let me know if my understanding is wrong.


这篇关于如何停止javascript中单击按钮的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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