取消提交code不工作 [英] cancel Submit code not working

查看:163
本文介绍了取消提交code不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的取消提交code的一个问题。
我已经使用的JavaScript code取消/停止我的网页上提交功能,但它不能正常工作。

I have a problem with my cancel submit code. I have used the javascript code for canceling/stopping the submit function on my page but it's not working properly.

这是工作在一些点,但还不够。我正在寻找一个解决这个问题,请尝试帮助我..

It is working in some point but it's not enough.. I'm looking for a solution to this problem please try to help me..

下面是我的code停止提交功能。

Here's my code for stopping the submit function..

 <script language="JavaScript">
 function mySubmit(evt)
 { 
   evt.preventDefault(); 
   try
   {
    someBug();
   }
   catch (e)
   {
    throw new Error(e.message);
   }
  return false;
  }
 }
</script>

和形式

<form id="form1" runat="server" onsubmit="return mySubmitFunction()">

起初似乎它的正常工作,因为我的页面不闪烁或刷新我点击一个按钮后,但突然我注意到,网页仍然是令人耳目一新,但其不闪烁..看看这张截图

At first it seems that it's working properly because my page is not blinking or refreshing after I click a button but suddenly I noticed that the page is still refreshing but its not blinking .. look at this screenshot

注意,标志是加载后,我点击移动到左边的按钮?看带箭头的红线。

Notice that the logo is loading after I click the move to left button? look at the red line with arrowhead ..

于是,我就用的OnClientClick函数,并把返回mySubmitFunction的,但同样的结果。

So I tried to use the onclientclick function and put the return mySubmitFunction in it but same result

下面是code

<asp:Button ID="Button2" runat="server" Text="&gt;&gt;&gt;" 
                    CssClass="button button-primary" 
onclick="Button2_Click" onclientclick="return mySubmitFunction()" />

希望你能帮助我这个谢谢我是新来的JavaScript ^ _ ^

hope you can help me with this thank you i'm new to javascript ^_^

我使用ASP.NET C#

I'm using ASP.NET C#

忽略的截图中的总数据^ _ ^我没有点击保存,这就是为什么它不是尚未更​​新。

Ignore the total data in the screenshot ^_^ I didn't click save that's why its not updating yet..

推荐答案

我看到,在标签你说你使用jQuery,这是可以做到轻松使用jQuery,而不是纯JavaScript,HRE你有一个例子。
HTTP://$c$cpen.io/xploshioOn/pen/ogJWKp

I see that in the tags you said you use jquery, this can be done easy with jquery instead pure javascript, hre you have an example. http://codepen.io/xploshioOn/pen/ogJWKp

HTML

<form id="form1">
  <input type="text">
  <input type="submit">
</form>

jQuery的

jquery

$('#form1').submit(function(e){
    e.preventDefault();
    alert("asd");
});

该警报只是要确保函数执行...

the alert is just to be sure the function is executing...

这篇关于取消提交code不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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