网络JavaScriptHTMLINPUT 地址拼接楊遠徵2022-01-222024-05-12方法一:使用按钮12345678910111213141516171819202122232425<!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> 方法二:使用回车12345678910111213141516171819202122232425<!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>