将值添加到URL使用Jquery进行表单提交 [英] Add Value To URL On Form Submit With Jquery

查看:116
本文介绍了将值添加到URL使用Jquery进行表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面提供这个表单时,我希望它为从php查询生成的6个url添加一个值。

 < form id =emailformaction =method =post> 
< input type =textvalue =size =30name =emailid =email>
< input type =submitname =submitvalue =Submitclass =continue-button>
< / form>

这是我的链接示例, sitename.com/demo.php ?1 = demo& 2 = haha​​ 如何使用表单和jquery将& email = formvalue 附加到URL中,使 sitename.com/demo.php?1=demo&2=haha = sitename.com/demo.php?1=demo&2=haha&email= formvalue



请注意,这些网址是通过查询动态生成的。



我尝试使用attr,但它不起作用。我知道你必须检查提交然后使用attr。$ / b
$ b $ $ p $ $''''''' {//听取提交事件

}


解决方案 div>

您可以使用像这样的隐藏字段

 < form action =method =post> 
< input type =hiddenname =new_valuevalue =value/>
< input type =textvalue =size =30name =email id =email>
< input type =submitname =submitvalue =Submitclass =continue-button>
< / form>

或者您可以添加到这种形式的操作

 < form action =http:// action_url?new_value = valuemethod =post> 
< input type =textvalue = size =30name =emailid =email>
< input type =submitname =submitvalue =Submitclass =continue-button>
< / form>


I have this form below when i submit it i want it to append a value to the 6 urls generated from a php query.

<form id="emailform" action="" method="post">
      <input type="text" value="" size="30" name="email" id="email">
      <input type="submit" name="submit" value="Submit" class="continue-button">
</form>

This is an example of my link, sitename.com/demo.php?1=demo&2=haha How can i use the form and jquery to append &email=formvalue to the url so sitename.com/demo.php?1=demo&2=haha = sitename.com/demo.php?1=demo&2=haha&email=formvalue ?

Please keep in mind that these urls are generated dynamically with a query.

I tried using attr on a but it doesnt work. I know you have to check for the submit then use attr.

$('#emailForm').submit(function(){ //listen for submit event

}

解决方案

You can use hidden field like this

<form action="" method="post">
      <input type="hidden" name="new_value" value="value"/>
      <input type="text" value="" size="30" name="email" id="email">
      <input type="submit" name="submit" value="Submit" class="continue-button">
</form>

or you can add to action of form like this

<form action="http://action_url?new_value=value" method="post">
      <input type="text" value="" size="30" name="email" id="email">
      <input type="submit" name="submit" value="Submit" class="continue-button">
</form>

这篇关于将值添加到URL使用Jquery进行表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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