HTML URL 使用用户输入创建

HTML URL creation using user input

我在 URL 末尾有一个 URL 作为 www.google.com 我需要添加三个用户输入。所以最终 URL 将是 google.com/a+b+c.

    <Html>
    <head>
    <body>
    <label for="ina">Input A:</label><br>
      <input type="text" id="ina" name="ina"><br><br>
    <label for="inb">Input B:</label><br>
      <input type="text" id="inb" name="inb"><br><br>
    <label for="inc">Input C:</label><br>
      <input type="text" id="inc" name="inc"><br><br>
    <a href="https://www.google.com"/input="ina"/input="inb"/input="inc" target="_blank">Submit</a>
    </body>
    </head>
</html>

使用JavaScript:

function submitForm() {
  var a = document.getElementById("ina").value;
  var b = document.getElementById("inb").value;
  var c = document.getElementById("inc").value;
  window.location='https://www.google.com/' + a + "+" + b + "+" + c;
}
<label for="ina">Input A:</label><br>
<input type="text" id="ina" name="ina"><br><br>
<label for="inb">Input B:</label><br>
<input type="text" id="inb" name="inb"><br><br>
<label for="inc">Input C:</label><br>
<input type="text" id="inc" name="inc"><br><br>
<button onclick="submitForm()">Submit</button>

或使用Window.open在新的tab/window中打开它:

function submitForm() {
  var a = document.getElementById("ina").value;
  var b = document.getElementById("inb").value;
  var c = document.getElementById("inc").value;
  window.open('https://www.google.com/' + a + "+" + b + "+" + c, "_blank");
}
<label for="ina">Input A:</label><br>
<input type="text" id="ina" name="ina"><br><br>
<label for="inb">Input B:</label><br>
<input type="text" id="inb" name="inb"><br><br>
<label for="inc">Input C:</label><br>
<input type="text" id="inc" name="inc"><br><br>
<button onclick="submitForm()">Submit</button>

(代码片段在 Stack Overflow 中不起作用,因为代码片段中不允许打开新的 windwos)