在提交后单击按钮,然后发布表单时,做一些js的事情 [英] do some js stuff when submit post the button is clicked and then post the form

查看:77
本文介绍了在提交后单击按钮,然后发布表单时,做一些js的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< input type ="submit">在其中
现在,我想在将表单发布到其操作URL之前进行一些客户端验证.我该怎么做呢.在此先感谢
我也想删除自动插入的字段__VIEWSTATE,__EVENTVALIDATION,因为它们没有任何作用
所以我该怎么做

i have a form with a <input type="submit"> in it
now i want to do some client side validation before the form is posted to its action url. how do i do this. thanks in advance
also i want to remove the automatically inserted fields __VIEWSTATE, __EVENTVALIDATION, as they dont serve me any purpose
so how do i do this

推荐答案

,您需要在表单标签上提交.看下面

< form action ="http://www.devinrolsen.com/" method ="post" onsubmit ="return validate();" name ="simpleForm">

在javascript中,您需要编写函数validate(),如果表单值确定,该函数将返回true,否则返回false
you need to onsubmit on form tag. Look at below

<form action="http://www.devinrolsen.com/" method="post" onsubmit="return validate();" name="simpleForm">

In javascript, you need to write the function validate() which will return true if the form values are OK otherwise return false


为什么不进行服务器端验证?有很多好处.由于它是.NET和C#,因此它可以更灵活,更容易开发. Javascrips通常需要花费更多的开发时间才能达到数量级.使用ASP.NET,您可以轻松地重新生成带有验证结果的同一页面,并将其呈现给用户.

—SA
Why not server-side validation? There are many benefits. It can be more flexible and easier to develop as this is .NET and C#. Javascrips usually takes more development time be the order of magnitude. With ASP.NET you can easily re-generate the same page with validation results and present it back to the user.

—SA


这篇关于在提交后单击按钮,然后发布表单时,做一些js的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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