Safari 不触发表单提交 [英] Safari does not trigger form Submit
问题描述
对于一个项目,我得到了两个通过 jquery trigger("submit") 发送的选择表单域;这在 Firefox 和 Chrome 中运行良好,但在 Safari 中没有任何反应.
For a project I got two select-formfields that get sent via jquery trigger("submit"); This works well in Firefox und Chrome, but in Safari nothing happens.
这是 HTML 代码:
This is the HTML-Code:
<body>
<form action="http://google.de" target="_blank" style="display: inline;" method="get">
<select class="bstarch2" data-role="none" name="q">
<option value="none">Please choose</option>
<option value="a: worked">A</option>
<option value="b: worked">B</option>
</select>
</form>
<select class="bstarch" data-role="none">
<option value="none">Please choose</option>
<option value="http://google.de">Google</option>
<option value="http://en.wikipedia.org">Wikipedia</option>
</select>
<form action="" method="get" target="_blank" id="mmform"></form>
</body>
这是 Javascript 代码:
And this the Javascript code:
$("body").on("change", ".bstarch", function () {
if ($(this).val() != "none") {
$("#mmform").attr("action", $(this).val());
$("#mmform").trigger("submit");
$(this).val("none");
}
});
$("body").on("change", ".bstarch2", function () {
if ($(this).val() != "none") {
$(this).parent().trigger("submit");
$(this).val("none");
}
});
我在这里有一个 jsfiddle,它也不适用于 Safari:http://jsfiddle.net/P7vNX/
I got a jsfiddle here, and as well it does not work with Safari: http://jsfiddle.net/P7vNX/
感谢您的帮助.
知道了:似乎 safari 阻止了表单作为弹出窗口提交.代码是正确的,但它被 Safari 阻止了...无法回答我的问题,因为我的名声很小.
推荐答案
在桌面 Mac 上使用 Safari 版本 11.1.2 (13605.3.8):如果在表单中指定了 target="_blank" 标签,提交表单失败.相同的表单在其他浏览器上按预期工作.删除 target="_blank" 规范,表单正常工作.带有 target="_blank" 的相同表单在其他浏览器(包括 Chrome、Firefox 和 IE)上也能正常工作.
Using Safari version 11.1.2 (13605.3.8) on a desktop Mac: if target="_blank" is specified within a form tag, submitting the form fails. That same form works as expected on other browsers. Remove the target="_blank" specification and the form works properly. The same form with target="_blank" does work as expected on other browsers including Chrome, Firefox and IE.
我只能假设这种不支持目标"属性的失败是 Safari 的缺陷.一种可能的解决方法是使用javascript:window.open()"而不是 URL 作为操作.
I can only assume this failure to support the "target" attribute is a Safari defect. A possible work-around would be to use "javascript:window.open()" instead of the URL as the action.
这篇关于Safari 不触发表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!