簡體   English   中英

基於文本輸入字段創建動態鏈接

[英]create dynamic link based on text input field

我正在嘗試制作一個文本輸入字段,訪問者可以在其中輸入一個值,然后點擊執行或提交。

根據數字編號,他們將被發送到新頁面。

例如,如果他們輸入 123 並點擊提交,它會將它們發送到http://www.example.com/page/123

有人可以幫我啟動並運行它嗎? 謝謝

我們去玩吧。 只需復制代碼並將其另存為 html。 你不需要 php 之類的。 需要服務器端代碼太簡單了。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

    $('#button').click(function(e) {  
        var inputvalue = $("#input").val();
        window.location.replace(" http://www.example.com/page/"+inputvalue);

    });
});
</script> 
</head>
<body>

       <input type="text" value="11" id="input"> 
       <button type="button" id="button">Click Me!</button>
</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM