简体   繁体   English

我们可以在一个表单中有多个提交类型按钮吗?

[英]Can we have more than one submit type button in one form?

I need to implement validation for a form but by two submit buttons?我需要通过两个提交按钮对表单进行验证?

Can we do change the 'Type' from jQuery so that it can work perfectly as i want:)我们可以更改 jQuery 中的“类型”,以便它可以按照我的意愿完美工作:)

If you are talking about client-side validation you can use JavaScript to make different buttons post to different locations (these locations can be different to validate it in more than one way on the server side) eg如果您正在谈论客户端验证,您可以使用 JavaScript 将不同的按钮发布到不同的位置(这些位置可以不同,以便在服务器端以多种方式验证它)例如

<form name="someForm1" id="someForm1" method="POST">
.
.
.


<input type="button" name="button1" id="button1" onclick="javascript:post1();"/>
<input type="button" name="button2" id="button2" onclick="javascript:post2();"/>
</form>

Then make post1 implement one type of client-side validation ( validate1() ) and post2 ( validate2() ) the other approach.然后让post1实现一种类型的客户端验证 ( validate1() ) 和post2 ( validate2() ) 另一种方法。 You can even use JavaScript to post to different URLs.您甚至可以使用 JavaScript 发布到不同的 URL。 An example of how this can be done is:如何做到这一点的一个例子是:

function post1()
{
  var form1=document.forms['someForm1'];
  form1.action="form1.aspx";
  if(validate1())
  {
     form1.submit();
  }
  else
  {
     invalid1();
  }    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM