从两个表单字段构建URL [英] Build URL from two form fields
问题描述
用户将在我们网站的两个文本字段中输入请求的数字,然后单击提交按钮。在这一点上,输入数据需要被插入URL并在浏览器中打开。
示例:URL.com/FixedData + UserEntry1 + FixedData + UserEntry2 - UserEntry1 &安培; UserEntry2将被插入到固定数据之间。
完成的URL将显示为: http://URL.com/FixedDataUserEntry1FixedDataUserEntry2
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
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屋!