FireFox 不要从 jQuery 脚本取消表单提交

发布于 2024-12-21 22:37:43 字数 1807 浏览 4 评论 0原文

我有这样的情况:

<form class="reqSnip" action="snipvw" method="post" target="_blank">
    <input type="hidden" name="a_snip" value="0">
    <input type="hidden" name="b_snip" value="1">
    <input type="hidden" name="fullDoc" value="true">
    <button type="submit" class="getFullSnippet"></button>
</form>

所以 - 带有 3 个隐藏字段+提交按钮的基本表单。在 jQuery 的帮助下,我绑定到提交此表单的时刻并自定义流程:

jQuery('.reqSnip').submit(function() {
    jQuery('#snipDIV').jqmShow(); // 1
    return false; // 2
});

为了使图片清晰:

  • // 1 - 在网页上打开一些“类似弹出”的窗口
  • // 2 - 取消表单提交。我这样做是因为表格只要求一些 Ajax-info 且不得执行标准表单提交。为了我的 你可以思考这个问题,因为我只是不想提交表单 地方,所有 Ajax 的东西都与这个问题无关。

所有这些如何协同工作:

  • 在 IE7/8/9/Chrome/Opera 中 - 一切如预期,弹出窗口打开,表单不打开 提交
  • 在 FireFox(Windows XP SP3 上的版本 8.0.1)中 - 弹出窗口打开并从 DO 提交(因此新选项卡出现在浏览器中)

我在 javascript 调试器中进行了简单的调查(我只是在 // 1 和 // 2 行上放置了 2 个断点(BP))以及我发现的事实:

  • IE7/8/9/Chrome/Opera - 在 // 1 行上点击 BP,然后在 // 2 行上点击 BP
  • FireFox - 在 // 1 行上点击 BP 并且永远不要在 // 2 行上点击 BP,所以 命令“return false”从未执行过:(

那么 - 如何使 FF 行为与所有其他浏览器中相同?

PS 第 1 行中使用的库:

更新< /strong>

我找到了问题的根源... 根据 jqModal 文档(请参阅上面的链接),如果绑定到 onShow 事件,则必须在事件处理程序内显示(设置可见)对话框(我的“类似弹出”的窗口)。所以一般方案是

var myOpen=function(hash){ hash.w.css('opacity',0.88).show(); }; 
$('#dialog').jqm({onShow:myOpen}); 
....
$('#dialog').jqmShow();

我编写的代码非常接近于此。 所有浏览器都接受这种方法。 FF“不喜欢”它。不知道为什么。因此,为了解决我的问题,不要绑定到 onShow 事件就足够了。那是!

I have that situation:

<form class="reqSnip" action="snipvw" method="post" target="_blank">
    <input type="hidden" name="a_snip" value="0">
    <input type="hidden" name="b_snip" value="1">
    <input type="hidden" name="fullDoc" value="true">
    <button type="submit" class="getFullSnippet"></button>
</form>

So - basic form with 3 hidden field+button to submit. With the help of jQuery I bind to the moment of submit this form and customize the process:

jQuery('.reqSnip').submit(function() {
    jQuery('#snipDIV').jqmShow(); // 1
    return false; // 2
});

To make picture clear:

  • // 1 - open some "pop-up-like" window over Web-page
  • // 2 - cancel form submit. I do so since the form just request some
    Ajax-info and must NOT perform standart form submission. For my
    question you can think as I just don't want the form submission take
    place, all Ajax-stuff is irrelevant for the question.

How all this works together:

  • In IE7/8/9/Chrome/Opera - all as expected, pop-up open, form don't
    submitted
  • In FireFox(ver. 8.0.1 on Windows XP SP3) - pop-up open and from DO
    submitted (so new tab appear in browser)

I make a light investigation in javascript debuggers (I just place 2 breakpoints(BP) on lines // 1 and // 2) and facts I discover:

  • IE7/8/9/Chrome/Opera - hit BP on line // 1, then BP on line // 2
  • FireFox - hit BP on line // 1 and NEVER hit BP on line // 2, so
    command 'return false' just never executed :(

So - how to make FF behaviour the same as in all others browsers?

P.S. Libraries used in line 1:

UPDATE

I found root of the problem...
According jqModal documentation (see link above) if you bind to onShow event you must to show (set visible) the dialog (my "pop-up-like" window) inside the event handler. So the general scheme will be

var myOpen=function(hash){ hash.w.css('opacity',0.88).show(); }; 
$('#dialog').jqm({onShow:myOpen}); 
....
$('#dialog').jqmShow();

I wrote my code very close to this.
All browsers accept this approach. FF "dislike" it. Have no idea why. So, to solve my problem it is enough DON'T bind to onShow event. That is!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-12-28 22:37:43

试试这个:

jQuery('.reqSnip').submit(function(e) {
    jQuery('#snipDIV').jqmShow(); // 1
    e.preventDefault(); // 2
});

Try this:

jQuery('.reqSnip').submit(function(e) {
    jQuery('#snipDIV').jqmShow(); // 1
    e.preventDefault(); // 2
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文