从两个表单字段构建URL [英] Build URL from two form fields

查看:133
本文介绍了从两个表单字段构建URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我们有两个表单字段,要求用户提供两个字母数字字符串,并且需要从这两个字符串中构建一个URL。但是,URL的基本结构需要保留。



用户将在我们网站的两个文本字段中输入请求的数字,然后单击提交按钮。在这一点上,输入数据需要被插入URL并在浏览器中打开。



示例:URL.com/FixedData + UserEntry1 + FixedData + UserEntry2 - UserEntry1 &安培; UserEntry2将被插入到固定数据之间。



完成的URL将显示为: http://URL.com/FixedDataUserEntry1FixedDataUserEntry2

解决方案

http://jsfiddle.net/4M3q3/



HTML:

 < input id =one>< input id =two> 
< button id =open>打开< /按钮>

JS:

  $('#open')。click(function(){
var fixedData1 ='http://www.google.com/#q=',
fixedData2 ='+ ',
userEntry1 = $('#one')。val(),
userEntry2 = $('#two')。val();

var newWindow = window .open(fixedData1 + userEntry1 + fixedData2 + two,'_blank');
newWindow.focus();
});


Essentially, we have two form fields asking for users to supply us with two alphanumeric strings, and a URL needs to be constructed from the two. However, there is a basic structure to the URL that needs to be kept in place.

Users will input the requested numbers in two text fields on our site, then click a submit button. At that point the input data needs to be inserted into the URL and opened in their browser.

Example: URL.com/FixedData + UserEntry1 + FixedData + UserEntry2 –– UserEntry1 & UserEntry2 will be inserted between the fixed data.

The finished URL would appear as: http://URL.com/FixedDataUserEntry1FixedDataUserEntry2

解决方案

http://jsfiddle.net/4M3q3/

HTML:

<input id="one"><input id="two">
<button id="open">Open</button>

JS:

$('#open').click(function() {
    var fixedData1 = 'http://www.google.com/#q=',
        fixedData2 = '+',
        userEntry1 = $('#one').val(),
        userEntry2 = $('#two').val();

    var newWindow = window.open(fixedData1 + userEntry1 + fixedData2 + two, '_blank');
    newWindow.focus();
});

这篇关于从两个表单字段构建URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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