Want html form submit to do nothing

2020-01-24 09:17发布

I want an html form to do nothing after it has been submitted.

action="" 

is no good because it causes the page to reload.

Basically i want an ajax function to be called whenever a button is pressed or someone hits "enter" after typing it data. Yes i could drop the form tag and add just call the function from the button's onclick event, but i also want the "hitting enter" functionality without getting all hackish.

9条回答
Viruses.
2楼-- · 2020-01-24 10:06

It also works:

<form id='my_form' action="javascript:myFunction(); return false;">
查看更多
做个烂人
3楼-- · 2020-01-24 10:06
<form onsubmit="return false;">
查看更多
时光不老,我们不散
4楼-- · 2020-01-24 10:08
<form id="my_form" onsubmit="return false;">

is enough ...

查看更多
登录 后发表回答