javascript 基于文本输入字段创建动态链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24266205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
create dynamic link based on text input field
提问by Reza Abbasian
I'm trying to make a text input field where visitors can enter a value and then hit go or submit.
我正在尝试制作一个文本输入字段,访问者可以在其中输入一个值,然后点击执行或提交。
Based on the digit number they would be send to a new page.
根据数字编号,他们将被发送到新页面。
For example if they enter 123 and hit submit it would send them to http://www.example.com/page/123
例如,如果他们输入 123 并点击提交,它会将它们发送到http://www.example.com/page/123
Could anybody please help me get this up and running? Thank you
有人可以帮我启动并运行它吗?谢谢
回答by Zardaloop
Here we go have fun. just copy the code and save it as html. you don't need php or such. it is way too simple to need a server side code.
我们去玩吧。只需复制代码并将其另存为 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>