【发布时间】:2021-04-28 17:17:46
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<!-- $("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://stackoverflow.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>Enter the DP ID below </label>
<br>
<input id="post_id" type="text">
<a id="link" href='https://www.google.com/search?'+post_id.value>Click to redirect</a>
</body>
</html>
How to create a link incorporating user input from the input box
我正在尝试一种类似的机制,但由于我对 HTML 太陌生,我无法快速使用 jquery。
感谢任何帮助!谢谢!
我的示例查询 - https://www.w3schools.com/code/tryit.asp?filename=GPZYOB9C4JFW
当我最初尝试这种方法时,生成的 url 有 [input object HTML] 这样的东西,而不是用户输入字符串。
【问题讨论】:
-
感谢您的快速回复。不胜感激,如果你能简单介绍一下
-
请在此处发布您的代码,而不是在外部站点。
-
post_id应该是post_id.value -
'code'
标签: html jquery url concatenation customization