Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

javascript - 如何在“提交”按钮onclick事件中取消表单提交?(How do I cancel form submission in submit button onclick event?)

I'm working on an ASP.net web application.(我正在开发ASP.net Web应用程序。)

I have a form with a submit button.(我有一个带有提交按钮的表格。) The code for the submit button looks like <input type='submit' value='submit request' onclick='btnClick();'> .(提交按钮的代码类似于<input type='submit' value='submit request' onclick='btnClick();'> 。) I want to write something like the following:(我想写类似以下内容的东西:) function btnClick() { if (!validData()) cancelFormSubmission(); } How do I do this?(我该怎么做呢?)   ask by Daniel Allen Langdon translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are better off doing...(你最好做...)

<form onsubmit="return isValidForm()" /> If isValidForm() returns false , then your form doesn't submit.(如果isValidForm()返回false ,则您的表单不提交。) You should also probably move your event handler from inline.(您可能还应该将事件处理程序从内联移动。) document.getElementById('my-form').onsubmit = function() { return isValidForm(); };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...