html input输入内容点击查询与url连接进行拼接
1.例如url为http://qinggx.cn/cx/
输入字符为:123456
最后拼接为http://qinggx.cn/cx/123456
并打开
2.
例如url为http://qinggx.cn/cx/拼接字符/xiazai/
输入字符为:123456
最后拼接为http://qinggx.cn/cx/123456/xiazai/
并打开
两种方式
辛苦各位大神
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<title>测试</title>
</head>
<body>
<div>
<input type="text" id="urlname"/>
<input value="查询" type="button" onclick="getUrlPath()"/>
</div>
</body>
<script>
var url = "http://qinggx.cn/cx/";
var url2 = "http://qinggx.cn/cx/拼接字符/xiazai/";
function getUrlPath() {
var urlName = $("#urlname").val();
url += url + urlName;
url2 = url2.replace('拼接字符', urlName);
console.log(url);
console.log(url2);
//window.location.href = url;//window.location.href = url2;
}
</script>
</html>
可以用js拼接
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>input地址拼接</title>
</head>
<body>
<div>
<input type="text" id="inputValue">
<button onclick="navigateTo()">拼接</button>
</div>
</body>
<script>
function navigateTo() {
var input_value = document.getElementById("inputValue").value;
alert(window.location + "/" + input_value)
// window.location.href="http://www.baidu.com" 跳转
}
</script>
</html>
第二种的话不知道是固定位置还是,如果固定位置可以用字符串截取插入变量再拼接;如果位置不固定可以考虑url参数,将变量赋给参数,然后合成地址。