【发布时间】:2015-05-05 18:12:32
【问题描述】:
我在这里得到了帮助来整理这段代码。它在 Chrome、Safari 和 Internet Explorer 中完美运行。但在 Firefox 中,它会重定向到一个子 URL(可能不是正确的词......)
我在页面上有脚本:
我想根据用户选择的值重定向到一个新页面(然后单击按钮):所以如果我选择选项 #2 我想到达这里:http://example.com/my-test-2
它适用于其他浏览器,但不适用于 Firefox。在 Firefox 中,它改为重定向到: http://example.com/test?redirect=http%3A%2F%2Fexample.com%2Fmy-test-2 这当然不会导致任何地方。
HTML 是在 jquery 和 Bootstrap 环境中加载的,我确实在该页面上使用了模式。我只是提到这一点,以防 Firefox 使用这些框架时出现已知错误。
这是 HTML:
I want to choose:
<form id="mychoice">
<input type="radio" name="redirect" value="http://example.com/my-test-1"><span>1</span><br>
<input type="radio" name="redirect" value="http://example.com/my-test-2"><span>2</span><br>
<input type="radio" name="redirect" value="http://example.com/my-test-3"><span>3</span><br>
<input type="radio" name="redirect" value="http://example.com/my-test-4"><span>4</span><br>
<input type="radio" name="redirect" value="http://example.com/my-test-5"><span>5</span><br /><br />
<input type="submit" value="See result">
</form>
javascript:
$(document).ready(function(){
$("#mychoice").submit(function(){
event.preventDefault();
var loc = $('input[name="redirect"]:checked').val();
window.location = loc;
return false;
});
});
你明白 Firefox 出现这种行为的原因吗?
如果有兴趣:我在 Mac OSX 10.10.2 上使用 Chrome 42.0.2311.90(64 位)、Firefox 37.0.2 和 Windows 8.1 IE 11.09600.17728
【问题讨论】:
-
Do you see the reason why Firefox behaves like this?你真的应该使用浏览器控制台调试你的代码,这会很快解决
标签: javascript jquery firefox