如何创建一个 link 合并来自输入框的用户输入

How to create a link incorporating user input from the input box

我正在寻找与网络系统的接口,其中包含由唯一代码定义的文章。

例如订单系统包含订单ORD001、ORD002

订单系统包含一个网站,每个订单都有自己独特的页面。

publicurl查看ORD001会是www.sampleorders.com/ORD001ORD002会是www.sampleorders.com/ORD002

我想阻止用户使用输入框,他们可以在其中输入他们的订单号,然后被路由到正确的网址。

有没有一种简单的方法可以使用 html 和 javascript 连接预定义字符串 (www.sampleorders.com/) 和表单用户输入 (ORD001)?

你可以使用 javascript and/or jquery。

尝试在下面的代码段中传递此 post ID(在 url 中)。

$("input#post_id").on("change", function(){ // Whenever this field changes

  var post_id = $("input#post_id").val(); // Get the value of the field
  
  $("a#link").attr("href", "https://whosebug.com/questions/" + post_id); // Update the href in the link to match the id inserted in the input field
  
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<label>Which post would you load ?</label>

<br>

<input id="post_id" type="text">

<a id="link" href="#">Go</a>