INPUT 地址拼接

方法一:使用按钮

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!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 + "/api/" + input_value)
window.location.href = (window.location + "/api/" + input_value)
}
</script>

方法二:使用回车

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!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" onkeyup="Enter()">
</div>
</body>
<script>
function Enter() {
var code = event.keyCode;
if (code == 13) {
alert('你按了回车键!');
var input_value = document.getElementById("inputValue").value;
window.location.href = (window.location + "/api/" + input_value)
}
}
</script>