重定向按钮
Button to redirect
基本上我有一个文本框,我希望当人们 paste/write 里面有一个网站,然后按下按钮,使用额外参数 ("/play/bonus")
<input name="website" id="website" type="text" />
<form method="POST" action=document.getElementById('website') & "/play/bonus">
<input name="pn" value="bonus" type="hidden">
<button id="bonus" class="btn btn-default navbar-element pull-center">
<b>50</b>
Satoshis
</button>
document.getElementById('website')
将给出该元素的对象。您需要使用 .value
.
document.getElementById('website').value
获取元素的值。
而且没有必要使用javascript,我是这么认为的。如果您使用 PHP
然后使用 PHP 的 header
函数进行重定向。
你的HTML:
<form method="POST" action="demo.php">
<input name="website" id="website" type="text" />
<input name="pn" value="bonus" type="hidden">
<input id="bonus" type="submit" class="btn btn-default navbar-element pull-center" Value="50 Satoshis">
</form>
你的demo.php文件将是这样的:
<?php
$redirect = $_POST['website'];
header("location:".$redirect."/play/bonus");
我会使用 Javascript 在代码中手动执行此操作,而不是制作表单 POST。
给你举个例子:
<html>
<head>
<title>JavaScript Form Redirection Example</title>
<script type="text/javascript">
function goToWebsite()
{
var url = document.getElementById("inputWebsite").value;
if (url != null)
{
url += "/play/bonus";
window.location.replace(url);
}
}
</script>
</head>
<body>
<form>
<input type="text" id="inputWebsite" placeholder="Website address"/>
<input type="button" value="Go!" onClick="goToWebsite()"/>
</form>
</body>
</html>
非常简单,它的作用是在单击按钮时运行 goToWebsite 函数。
goToWebsite 函数:
- 获取文本框中URL的值
- 检查以确保 URL 不为空
- 在其末尾添加 /play/bonus
- 使网络浏览器重定向到该页面。
基本上我有一个文本框,我希望当人们 paste/write 里面有一个网站,然后按下按钮,使用额外参数 ("/play/bonus")
<input name="website" id="website" type="text" />
<form method="POST" action=document.getElementById('website') & "/play/bonus">
<input name="pn" value="bonus" type="hidden">
<button id="bonus" class="btn btn-default navbar-element pull-center">
<b>50</b>
Satoshis
</button>
document.getElementById('website')
将给出该元素的对象。您需要使用 .value
.
document.getElementById('website').value
获取元素的值。
而且没有必要使用javascript,我是这么认为的。如果您使用 PHP
然后使用 PHP 的 header
函数进行重定向。
你的HTML:
<form method="POST" action="demo.php">
<input name="website" id="website" type="text" />
<input name="pn" value="bonus" type="hidden">
<input id="bonus" type="submit" class="btn btn-default navbar-element pull-center" Value="50 Satoshis">
</form>
你的demo.php文件将是这样的:
<?php
$redirect = $_POST['website'];
header("location:".$redirect."/play/bonus");
我会使用 Javascript 在代码中手动执行此操作,而不是制作表单 POST。
给你举个例子:
<html>
<head>
<title>JavaScript Form Redirection Example</title>
<script type="text/javascript">
function goToWebsite()
{
var url = document.getElementById("inputWebsite").value;
if (url != null)
{
url += "/play/bonus";
window.location.replace(url);
}
}
</script>
</head>
<body>
<form>
<input type="text" id="inputWebsite" placeholder="Website address"/>
<input type="button" value="Go!" onClick="goToWebsite()"/>
</form>
</body>
</html>
非常简单,它的作用是在单击按钮时运行 goToWebsite 函数。
goToWebsite 函数:
- 获取文本框中URL的值
- 检查以确保 URL 不为空
- 在其末尾添加 /play/bonus
- 使网络浏览器重定向到该页面。