2

给定以下功能:

window.onbeforeunload= function() {
    if (CKEDITOR.instances.stuff.getData().length > 0 && oktoquit == false) {
        return "You have unsaved changes. Click Cancel now, then 'Save' to save them. Click OK now to discard them.";
    }
};

如果用户单击带有 ID 的 div 中的链接,我想要一种方法来排除此函数的运行:

<div id="ignore me"><a href="">blah</a><a href="">blah</a><a href="">blah</a></div>

有任何想法吗?

** 更新原来是该网站搜索的以下代码导致了问题。但为什么?

$("#searchresults li").live('click', function(e) {
    if (e.target.nodeName != "a") {
        window.location = $(this).find('a').attr('href');
    }
});
4

2 回答 2

1

你可以这样做:

$("#ignoreMe").click(function() {
  window.onbeforeunload = null;
});

我将您的 ID 更改为ignoreMe有效,但您明白了 :) 从您的问题来看,您可能需要#ignoreMe a一个选择器,如果您想从执行处理程序中排除该 div 内的任何链接,无论您想要什么,只需使用那个选择器。

于 2010-04-18T02:58:04.877 回答
0

window.top.onbeforeunload 这忽略了完成这项工作的 CKEDITOR iFrame

于 2010-04-18T19:53:52.303 回答