如何使用JavaScript提交表单并重定向到URL? [英] How to submit form using JavaScript and redirect to a URL?

查看:121
本文介绍了如何使用JavaScript提交表单并重定向到URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JavaScript提交表单并重定向到URL?

 < form name =f1method = getaction =aaa.php> 
名称:< input type =textname =value_1value =/>< br>
年龄:< input type =textname =value_2value =/>
< input type =submitname =submitvalue =send/>
< / form>

请点击此链接中的图片:

http://image.ohozaa.com/i/4d0/zCzQIH.jpg

按下提交按钮后,我想将页面重定向到 www.example.com/aaa/robert/21



我该怎么做? 试试这个与HTML代码

 < form name =f1method =getaction =aaa.php> 
name:< input type =textid =value_1name =value_1value =/>< br>
年龄:< input type =textid =value_2name =value_2value =/>
< input type =buttonname =submitonclick =checkredirect()value =send/>

和javascript

 < script type =text / javascript> 
函数checkredirect(){
var value_1 = $('#value_1')。val();
var value_2 = $('#value_2')。val();
window.location ='http://www.example.com/'+value_1+'/'+value_2;
返回false;
}
< / script>

不要忘记添加jQuery库


How to submit form using JavaScript and redirect to a URL ?

<form name="f1" method="get" action="aaa.php">
    name : <input type="text" name="value_1" value=""/><br>
    age: <input type="text" name="value_2" value=""/>
    <input type="submit" name="submit" value="send"/>
</form>

please see image in this link:

http://image.ohozaa.com/i/4d0/zCzQIH.jpg

after press submit button , i want to redirect page to www.example.com/aaa/robert/21

How can i do that ?

解决方案

Try this with html code

<form name="f1" method="get" action="aaa.php">
name : <input type="text" id="value_1" name="value_1" value=""/><br>
age: <input type="text" id="value_2" name="value_2" value=""/>
<input type="button" name="submit" onclick="checkredirect()" value="send"/>

And javascript

<script type="text/javascript">
function checkredirect(){
    var value_1 = $('#value_1').val();
    var value_2 =  $('#value_2').val();
    window.location = 'http://www.example.com/'+value_1+'/'+value_2;
    return false;
}
</script>

Don't forget to add jQuery library

这篇关于如何使用JavaScript提交表单并重定向到URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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