如何在提交表单后停止跳转到顶部的页面? [英] How to stop a page jumping to the top once a form is submitted?

查看:113
本文介绍了如何在提交表单后停止跳转到顶部的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从哪里可以输入数值的地方。表格在更改或输入时提交,具体取决于他们想要更改的值。提交的值以相同的形式进行计算。
问题:
一旦提交了值,页面就跳回顶端。有办法阻止这种情况的发生。我想停止窗体上方的div标签。



表单看起来像这样

 < div id =a>< / div> 
< div id =b>< / div>
< div id =c>< / div>
< / form action =mypage.php#selfsubmitmethod =postid =self submit>

< input name =field1type =textonkeydown =if(event.keyCode == 13){this.form.submit(); return false;}之间的一些计算} size =10value =>
< select name =field2onchange =this.form.submit()>
< option value =w> w< / option>
< option value =x<?php if($ _POST ['field2'] == x){echo ($ _POST ['field2'] == y){echo'='选择';}?>> x< / option>
< option value =y ($ _POST ['field'] == z){echo'='选择';}?>> y< / option>
< option value = selected ='selected';}?>>> z< / option>
< / select>
一些更多计算
< / form>

我希望它能提交表单,一旦提交就不会跳到页面的顶部。
有没有办法做到这一点?任何帮助欢迎

解决方案

在这里,试一试:

注意:多个< br> '仅用于测试目的。



您可以将a

< a name =selfsubmit>< / a> p> 代码

;<峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br>
< br>< br>< br>< br>< br>< br>< br>< br>< br>

< div id =a>< / div>
< a name =selfsubmit>< / a>
< div id =b>< / div>
< div id =c>< / div>
< form action =mypage.php#selfsubmitmethod =post>

< input name =field1type =textonkeydown =if(event.keyCode == 13){this.form.submit(); return false;}之间的一些计算} size =10value =>
< select name =field2onchange =this.form.submit()>
< option value =w> w< / option>
< option value =x<?php if($ _POST ['field2'] == x){echo ($ _POST ['field2'] == y){echo'='选择';}?>> x< / option>
< option value =y ($ _POST ['field'] == z){echo'='选择';}?>> y< / option>
< option value = selected ='selected';}?>>> z< / option>
< / select>
更多计算
< input type =submitname =submit value =Submit>

< / form>

< br>< br>< br>< br>< br>< < br>< br>< br>< br>< br>< br>< br>< br>< br> ;< br>< br>< br>< br>< br>< br>< br>< br> < br>< br>< br>< br>< br>< br>< br>< br>< br> ;< BR><峰; br><峰; br><峰; br><峰; br>

< br>< br>< br>< br>< br>< br>< br> BR>
< br>< br>< br>< br>< br>< br>< br>< br>< br>

另外,您的表单中有语法错误:

 < / form action =mypage.php#selfsubmitmethod =postid =self submit> 
--- ^

应该读作:

 < form action = 

< / form 前面有一个 / ,肯定会让你头痛。


I have got a from where people can input values. The form is submitted on change or on enter depending which value they want to change. The submitted values are used in the same form to calculate. The problem: once the values are submitted the page jumps back to the top. Is there way to stop this from happening. I would like to stop the page on a div tag just above the form.

The form looks something like this

<div id ="a"></div>
<div id ="b"></div>
<div id ="c"></div>
</form action="mypage.php#selfsubmit " method="post" id="self submit">
some calculations in between
<input name="field1" type="text" onkeydown="if (event.keyCode == 13) { this.form.submit(); return false; }" size="10" value= "">
<select name="field2" onchange="this.form.submit()" >
       <option value="w >w</option>
    <option value="x"<?php if ($_POST['field2']==x) {echo "selected='selected'"; } ?>>x</option>
    <option value="y"<?php if ($_POST['field2']==y) {echo "selected='selected'"; } ?>>y</option>
    <option value="z"<?php if ($_POST['field']==z) {echo "selected='selected'"; } ?>>z</option>
  </select>
some more calculations
</form>

I would like it to submit the form how ever once submitted don't jump to the top of the page. At the minute it stops where the form start because of the #selfsubmit. I would like it to stop on e.g. div b. Is there a way to do this? Any help welcome

解决方案

Here, give this a try:

Note: Multiple <br>'s are for testing purposes only.

You can place the anchor tag <a name="selfsubmit"></a> anywhere you want, after submission.

Code:

<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>

<div id ="a"></div>
<a name="selfsubmit"></a>
<div id ="b"></div>
<div id ="c"></div>
<form action="mypage.php#selfsubmit" method="post">
some calculations in between
<input name="field1" type="text" onkeydown="if (event.keyCode == 13) { this.form.submit(); return false; }" size="10" value= "">
<select name="field2" onchange="this.form.submit()" >
    <option value="w >w</option>
    <option value="x"<?php if ($_POST['field2']==x) {echo "selected='selected'"; } ?>>x</option>
    <option value="y"<?php if ($_POST['field2']==y) {echo "selected='selected'"; } ?>>y</option>
    <option value="z"<?php if ($_POST['field']==z) {echo "selected='selected'"; } ?>>z</option>
  </select>
some more calculations
<input type="submit" name="submit" value="Submit">

</form>

<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>

<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>

<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>

Plus, you have a syntax error in your form:

  </form action="mypage.php#selfsubmit " method="post" id="self submit">
---^

which should read as:

<form action=

There is a / in front of </form that will surely cause you headaches.

这篇关于如何在提交表单后停止跳转到顶部的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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