如何在提交之前添加其他字段以形成表单? [英] How to add additional fields to form before submit?
本文介绍了如何在提交之前添加其他字段以形成表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以使用javascript和JQuery添加一些额外的字段,使用POST从HTTP表单发送?
Is there a way to use javascript and JQuery to add some additional fields to be sent from a HTTP form using POST?
我的意思是:
<form action="somewhere" method="POST" id="form">
<input type="submit" name="submit" value="Send" />
</form>
<script type="text/javascript">
$("#form").submit( function(eventObj)
{
// I want to add a field "field" with value "value" here
// to the POST data
return true;
}
</script>
推荐答案
是的,您可以尝试使用一些隐藏的参数。
Yes.You can try with some hidden params.
$("#form").submit( function(eventObj) {
$('<input />').attr('type', 'hidden')
.attr('name', "something")
.attr('value', "something")
.appendTo('#form');
return true;
});
这篇关于如何在提交之前添加其他字段以形成表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文