admin管理员组文章数量:1287884
When defining a <form>
, it is possible to set the action
tag.
How can I set it to null (#), so that it will not actually change the page?
When defining a <form>
, it is possible to set the action
tag.
How can I set it to null (#), so that it will not actually change the page?
Share Improve this question edited Apr 28, 2014 at 3:42 danielschemmel 11.1k1 gold badge39 silver badges59 bronze badges asked Jan 19, 2011 at 16:04 norris1023norris1023 6333 gold badges16 silver badges25 bronze badges 2- 5 I cannot understand this question. – Josiah Ruddell Commented Jan 19, 2011 at 16:08
- You're going to have to clarify this because currently it makes no sense. – Pointy Commented Jan 19, 2011 at 16:11
5 Answers
Reset to default 4A bit hard to understand but I think what you want is this:
<form action="#">
<!-- code here -->
</form>
A <form>
tag without an action
attribute will send the data to the page it was submitted from.
You only need to use the action
attribute if you're sending the form data to a different page.
<form method="GET">
<input type="text" size="10" name="input" value="default">
<input type="submit" value="Submit">
</form>
(NOTE: This does not work on the file:///
protocol handler.)
For anyone else reading this, it is usually better to have your input or button object return false; when it's clicked. This will make sure the form doesn't follow an action, and instead stays on the page. It would be similar conceptually to what is being asked, as in it will stay on the current page.
This let's you handle submit options in javascript.
Here's an example of how you would submit an email address to your API route, alerting the user what is returned by the API call:
HTML:
<form>
<input type="text" name="email">
<button onclick="do_something(); return false;"
</form>
JAVASCRIPT:
var do_something = function(){
$.ajax({
url: "http://myapi./route",
type: 'POST',
data: $('form').serialize(),
context: document.body
}).done(function(data) {
alert(data);
});
};
You can set form action to null in the following way. This worked for me.
< form action ='' >
Try This
<form method="dialog">
<input type="text" size="10" name="input" value="default">
<input type="submit" value="Submit">
</form>
本文标签: javascriptHow do you do the action for a form be nullStack Overflow
版权声明:本文标题:javascript - How do you do the action for a form be null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741332163a2372827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论