如何使 HTML 按钮不重新加载页面 [英] How do I make an HTML button not reload the page

查看:31
本文介绍了如何使 HTML 按钮不重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮().单击它时,页面会重新加载.由于我有一些在页面加载时调用的 jQuery hide() 函数,这会导致这些元素再次隐藏.如何让按钮什么都不做,以便我仍然可以添加一些在单击按钮时发生的动作但不重新加载页面.

I have a button (<input type="submit">). When it is clicked the page reloads. Since I have some jQuery hide() functions that are called on page load, this causes these elements to be hidden again. How do I make the button do nothing, so I can still add some action that occurs when the button is clicked but not reload the page.

推荐答案

不需要 js 或 jquery.要停止页面重新加载,只需将按钮类型指定为按钮".如果您不指定按钮类型,浏览器会将其设置为重置"或提交",从而导致页面重新加载.

there is no need to js or jquery. to stop page reloading just specify the button type as 'button'. if you dont specify the button type, browser will set it to 'reset' or 'submit' witch cause to page reload.

 <button type='button'>submit</button> 

这篇关于如何使 HTML 按钮不重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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