根据文本输入字段创建动态链接

Rez*_*ian 2 javascript php forms hyperlink location-href

我正在尝试创建一个文本输入字段,访问者可以在其中输入值,然后点击或提交.

根据数字编号,他们将发送到新页面.

例如,如果他们输入123并点击提交,则会将其发送到http://www.example.com/page/123

有人可以帮我解决这个问题吗?谢谢

Far*_*ani 13

在这里,我们玩得开心.只需复制代码并将其另存为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>
Run Code Online (Sandbox Code Playgroud)