jQuery转到表单提交中的URL,并将字段值添加到URL字符串中 [英] jquery to goto a url on form submit with field values added to the url string
问题描述
我对jquery还是很陌生,我认为这很简单,但是我很挣扎,而Google似乎并没有帮助....
I'm fairly new to jquery and I think this is simple but I'm struggling and google doesn't seem to be helping....
我所拥有的是一种基本形式...
What I have is a basic form...
<form>
First Name: < input type="text" name="firstName" id="firstName" />
Surname: < input type="text" name="surname" id="surname" />
<input type="submit" id="submit" value="submit"/>
</form>
现在单击提交时,我想转到一个URL,然后将froms值添加到url字符串中(但不使用form method = get形式),我基本上希望做到这一点
Now when submit is clicked I want to goto a url but then add the froms values to the url string (but not using the form method=get) basicly I want this to happen
点击提交后转到http://myurl.com/index.html?params=firstNamevalue*surnamevalue
我一直在研究jquery,但是我一直在做这样的事情...
I've been hacking about with the jquery but where I'm upto is something like this...
< script src="http://www.google.com/jsapi" type="text/javascript">< /script>
< script type="text/javascript">
google.load("jquery", "1.3.1");
</script>
< script type="text/javascript">
var = firstName $("#firstName").val();
var = surname $("#surname").val();
$('#submit').click(function(){
window.location = ???;
});
< /script>
希望我早已清楚了-非常感谢您的帮助!
hopefully I've been farily clear - I'd greatly appreciate any help!
安迪
推荐答案
谢谢你们在此方面的帮助...
thank you both for your help on this...
我不确定我的方法是否在做错事,或者我没有描述我需要做的足够好...
I'm not sure if I was doing something wrong with your methods or if I hadn't described what I needed to do well enough...
最终我的解决方案是...
The solution in the end for me was this...
第一个文件包含一个带有method="get"
first file contains a a form with method="get"
< form method="get" action="getParams.html">
First Name: < input type="text" name="firstName" id="firstName" />
Surname: < input type="text" name="surname" id="surname" />
< input type="submit" id="submit" value="submit"/>
< /form>
这指示获取参数,并且随着method = get url以getParams.html?firstname=""&surname=""
this directs to get params and as the method=get the url ends with getParams.html?firstname=""&surname=""
然后在getParams.html
页面中,此代码仅用于从url格式化(如我所需要的那样)并重定向...
Then in the getParams.html
page this is simply used for the formatting (as i need it to be) from the url and redirect...
我在此插件http : // projects.allmarkedup.com/jquery_url_parser/
与js:
var firstName = jQuery.url.param("firstName");
var surname = jQuery.url.param("surname");
location.href = 'http://myOnlineMag/issue01.html?params=' + firstName + '*' + surname;
将我想要的值作为vars拉出url,然后将它们附加到我的url的末尾. (我需要使用这种特定格式的文件-在项目上线之前不能共享链接,但是如果您愿意,我可以在下周发布.)
pulls the values I want form the url as vars then attaches them to the end of my url. (I needed these in this specific format - can't share a link until the projects live but I can post next week if you would like.)
这篇关于jQuery转到表单提交中的URL,并将字段值添加到URL字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!