我如何提交表单,并在同一时间移动到下一页

How can i submit form and move to the next page both at a time?

本文关键字:同一时间 移动 一页 表单 何提交 提交      更新时间:2023-09-26

我的HTML代码部分:

<form method="post" id="form">
<input type="number" min="0" max="20" id="experience" required name="experience"title="experience" class="formfield" />
<input type="image" id="registersubmit4" name="registersubmit4" src="images/arrow-right.png"  title="next"/>
</form>

我想提交表单时,用户点击下一个和提交后,然后移动到下一页。

<input type="image">

可以很好地提交,但提交后我想移动到下一页。

我使用javascript onclick()事件如下:

<input type="image" onclick=form.submit(); "location='next.html'">

这不起作用。请帮助……

这通常通过在表单上指定一个操作来完成:

<form method="post" action="newpage.html" id="form">

…但是,如果处理表单的页面与您想要访问的页面不同,则可以使用服务器端重定向。如何工作将取决于您使用的服务器端语言。

我用这个来解决我的问题。

jQuery(window).attr("location", "your page or external link goes here");

看一下jQuery.post。你可以试试这样做。

<script>
  // Attach a submit handler to the form
  $( "#form" ).submit(function( event ) {
    // Stop form from submitting normally
    event.preventDefault();
    // Get some values from elements on the page:
    var $form = $( this ),
        exp = $form.find( "input[name='experience']" ).val(),
        url = $form.attr( "action" );
    // Send the data using post
    var posting = $.post({
      url: url,
      data: { experience: exp } );
      success: function( data ) {
        window.location='next.html';
      }
    });
  });
</script>