Javascript 如何在不使用提交按钮的情况下提交表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14826757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can one submit a form without using submit button
提问by Anon30
I am new to JavaScript & php.
我是JavaScript 和 php 的新手。
How can one submit a form without using submit button?
如何在不使用提交按钮的情况下提交表单?
if possible without using anchor tag.
如果可能,不使用锚标记。
Please guide me how to achieve this task.
请指导我如何完成这项任务。
回答by
just use following code
只需使用以下代码
<form id="jsform" action="whatever you want">
// input fields
</form>
<script type="text/javascript">
document.getElementById('jsform').submit();
</script>
回答by Sumit Bijvani
you can submit it with the use of javascript submit()function
您可以使用javascriptsubmit()函数提交它
<script type="text/javascript">
function submitform()
{
document.forms["myform"].submit();
alert("Value is sumitted");
}
</script>
<form id="myform" action="submit.php" method="post">
Search: <input type="text" name="query">
<a href="javascript: submitform()">Submit</a>
</form>
回答by Imtiaz Zaman Nishith
I think you can make your submit button's visibility 'hidden' and use the following javascript.
我认为您可以将提交按钮的可见性设置为“隐藏”并使用以下 javascript。
<script type="text/javascript">
// Using jQuery.
$(function() {
$('form').each(function() {
$('input').keypress(function(e) {
// Enter pressed?
if(e.which == 10 || e.which == 13) {
this.form.submit();
}
});
$('input[type=submit]').hide();
});
});
</script>
<form name="formName" method="post">
<input name="someName" type="text" /><br />
<input name="somePass" type="password" />
<input type="submit" style="visibility: hidden;" />
</form>
回答by Sergio Canseco
In javascript it must use the form submit()method implemented in a custom button or anchor.
在 javascript 中,它必须使用在自定义按钮或锚点中实现的表单submit()方法。
In PHP you can use the curllibrary (client URL library).
在 PHP 中,您可以使用curl库(客户端 URL 库)。

