好的。我提供了一个表单,它在提交时通过JavaScript来决定将用户接下来的页面。表单提交和JavaScript在IE,Firefox或Safari中不起作用;在Chrome中工作正常
当我在我的IDE(Coda 2)中预览它时,以及在Chrome中预览时,一切正常。但是,当我在Firefox,IE(任何版本)或Safari中打开相同的页面时,我无法越过第一页。
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title>
<link href="eh_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<nav id="navWrapper" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">Site Title</a>
</div>
<div class="link-container">
<ul>
<li><a href="http://www.link.net">LinkText</a></li>
<li><a href="mailto:[email protected]?subject:Help”>Help</a></li>
</ul>
</div>
</div>
</nav>
<div class="main-container">
<div class="page-container">
<form onsubmit="OpenWindow()" id="page1" action="" method="post">
<fieldset id="mainSelection">
<label><input type="radio" class="radio-button" value="A" name="sel1"> Option A</label><br />
<label><input type="radio" class="radio-button" value="B" name="sel1"> Option B</label><br />
<label><input type="radio" class="radio-button" value="C" name="sel1"> Option C</label><br />
<label><input type="radio" class="radio-button" value="D" name="sel1"> Option D</label><br />
</fieldset><br />
<input type="submit" value="Next" id="submitButton" form="page1">
</form>
</div><!--page-container-->
</div><!--main-container-->
<footer class="site-footer">
Footer Text
</footer>
<script type="text/javascript" language="javascript">
function OpenWindow() {
var choice = document.getElementById("page1");
choice = choice.sel1.value;
if (choice == 'A') {
window.open('result1.html','_self');
} else if (choice == 'B') {
window.open('page2.html','_self');
} else if (choice == 'C') {
window.open('page3.html','_self');
} else if (choice == 'D') {
window.open('page4.html','_self');
}
return: false;
}
</script>
</body>
</html>
我不知道是怎么回事。非常感激任何的帮助。
每几个建议,我已经添加了return: false;
声明到我的脚本的结尾,但事情仍然无法正常工作。
命中F12。转到脚本调试器。调试您的页面。 (另外,你的openWindow函数应该返回false) – EricLaw
我对你在页面中包含jquery的事实很感兴趣,但在代码中使用纯JS代码 但是我的猜测是EricLaw会提到,因为你的openwindow函数不是' t返回false表单将数据提交到同一页面。 – user1094553
@ user1094553这是我第二次与JS混淆 - 我不确定是否需要包含jQuery或不让它正常运行。 – andrewdcato