单击表单内的按钮时防止刷新页面 [英] prevent refresh of page when button inside form clicked
本文介绍了单击表单内的按钮时防止刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单内使用按钮时遇到问题.我想要那个按钮来调用函数.确实如此,但会刷新页面.
I have an issue while using buttons inside form. I want that button to call function. It does, but with unwanted result that it refresh the page.
我的简单代码是这样的
<form method="POST">
<button name="data" onclick="getData()">Click</button>
</form>
点击按钮时,该函数被调用并刷新页面,这会重置我之前的所有请求,这些请求会影响作为前一个请求的结果的当前页面.
On clicking the button, the function gets called with page refreshed, which resets all my previous request which affects the current page which was result of the previous request.
如何防止页面刷新?
推荐答案
让 getData()
返回 false.这将修复它.
Let getData()
return false. This will fix it.
<form method="POST">
<button name="data" onclick="return getData()">Click</button>
</form>
这篇关于单击表单内的按钮时防止刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文