改变页面
我想成立一个JS当用户按下按钮,将其重定向到主页,名为index.html改变页面
<form method="confirm" style="width: 500px; height: 300px; margin-left: auto; margin-right: auto; margin-top:100px; margin-bottom: 100px; font-size: 30px; color: black;">
<fieldset id="confirm">
<legend>NOTIFICATION</legend>
<table>
<tr>
<td>
<h1>THANK YOU FOR SIGNING IN</h1>
</td>
</tr>
<td>
<input type="submit" value="Return to homepage" onclick="return return1();">
<script>
function return1()
{
window.location.href = 'index.html';
}
</script>
</td>
</tr>
</table>
</fieldset>
</form>
添加返回false的功能禁用默认事件在提交(页面刷新)
function return1()
{
window.location.href = 'index.html';
return false;
}
我确实添加了返回false但仍然不能正常工作:) – 2014-10-04 08:17:32
您是否在控制台中遇到错误? – 2014-10-04 08:19:14
到目前为止没有错误 – 2014-10-04 08:19:54
更换
window.location.href = 'index.html';
有:
window.open('INDEX.HTML');
下面的代码我重定向到index.php这在同级别的index.html坐着index.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="check.php" method="post" id="re">
<fieldset id="confirm">
<legend>NOTIFICATION</legend>
<table>
<tr>
<td>
<h1>THANK YOU FOR SIGNING IN</h1>
</td>
</tr>
<td>
<input type="submit" value="Return to homepage">
</td>
</tr>
</table>
</fieldset>
</form>
<script src="index.js"></script>
</body>
</html>
JS文件
function _x(elem){
return document.getElementById(elem);
}
var x = _x("re");
x.onsubmit = function(e){
e.preventDefault();
window.location = "index.php";
}
有一些失误这里。
你得到的错误是因为你用一个表单内提交输入按钮,该按钮将试图评估您的表单提交。为了防止你必须在你的函数上返回false。
<script>
function return1()
{
window.location.href = 'index.html';
return false;
}
</script>
但是,如果你想要做一个按钮,简单地重定向到另一个页面,你不应该使用形式和一个提交按钮,但只是一个普通的输入按钮
<input type="button" value="Return to homepage" onclick="return1();">
如果你想使用的形式,因为要计算一些数据,你需要把你的页面上的action
领域<form>
,而无需使用脚本
也证实是不能接受的,你应该使用GET
或POST
。
<form method="POST" action="index.html">
简单地改变你的输入型submit
到button
<input type="button" value="Return to homepage" onclick="return return1();">
您更改代码
<input type="submit" value="Return to homepage" onclick="return return1();">
=><a href="index.html" class="btn">Return to homepage</a>
以键入CSS “.btn” 看到像按钮
注意:在表单中,如果不提交表单,则不应放置或重定向。
这可能会帮助你
<script language="javascript">
function return1()
{
window.location="yourpage.html";
}
</script>
这里有什么问题? 。 。 。 。 – rorofromfrance 2014-10-04 08:09:01
我认为他的东西不起作用。 – 2014-10-04 08:09:38
当我点击按钮时,它不会将我重定向到索引页:) – 2014-10-04 08:09:53