阻止使用javascript重定向/刷新表单提交 [英] prevent form submit from redirecting/refreshing using javascript

查看:651
本文介绍了阻止使用javascript重定向/刷新表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,您可以在一系列texboxes(从php生成)中输入数据,以及2个按钮GetData和SaveData。我希望能够在编辑文本框时按下回车键,它将执行与单击SaveData按钮(onclick =onSave();)相同的操作。我可以做到以下几点:

 < form id =editFormname =editFormaction =onSave ();> 

但是当我按回车时,页面被重定向到页面,没有php post(例如。 :www.mypage.com/index.php,而不是www.mypage.com/index.php?edit_data=true)



我如何实现我想要的?

解决方案

答案是(感谢Ulysses回答部分问题):

 < form id =editFormname =editFormonsubmit =onSave(); return false;> 

我的onSave();函数确实返回false,但由于它正在进行重定向,所以我不得不在onSave()之后返回false。 (解释为什么??)

谢谢!


I have a page where you can enter data within a series of texboxes (generated from php), and 2 buttons, GetData and SaveData. I want to be able to press enter when editing the texboxes, and it would perform the same action as clicking the SaveData button (onclick="onSave();"). I can acheive this by doing the following:

<form id="editForm" name="editForm" action="onSave();">

but when I press enter, the page is redirected to the page, without the php post (ex.:www.mypage.com/index.php, instead of www.mypage.com/index.php?edit_data=true)

How do I achieve what I want?

解决方案

The answer was (thanks to Ulysses for part fo the answer):

<form id="editForm" name="editForm" onsubmit="onSave();return false;">

My onSave(); function did return false, but since it was doing the redirection, I had to put the return false after the onSave(); (explain why??)

Thanks!

这篇关于阻止使用javascript重定向/刷新表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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