【发布时间】:2012-04-10 15:03:06
【问题描述】:
...或者为什么 $(this).dialog() 在使用动态 HTML 时在 Firefox 中会失败?
我有一个点击事件,它在网页上打开一个 jQuery 模式对话框,它在 Chrome 和 IE 中运行良好,但在 Firefox 中却不行。
下面是相关代码:
var dialogId = 'uniqueName-' + Math.floor(Math.random() * 1000)
var dialogDiv = $(document.createElement('div')).attr("id", dialogId);
dialogDiv.load(this.href, function () {
var dialog = $(this).dialog({ autoOpen: false });
...
});
在 Firefox 11 中,$(this).dialog({ autoOpen: false }) 失败并显示以下错误消息:
$(this).dialog 不是函数
但在 IE 9 和 Chrome 17 中一切正常。有什么线索吗?
更新:
这是上面代码所在的document.ready 函数。我删除了它以简化事情。 ALERT A 发生在 ALERT B 之前。ALERT A 显示[object Object]。当我点击链接并显示'undefined' 时,会出现警报 B。
$(function () {
alert($.ui); // ALERT A
// Wire up the click event of any dialog links
$('.dialogLink').live('click', function () {
alert($.ui); // ALERT B
return false;
});
});
更新 2:
既然我指出了问题的出处,我重新表述了我的问题,并在此处发布了重现原始问题的最少代码:Why is FF on OS X losing jQuery-UI in click event handler?
【问题讨论】:
-
你能用console.log或者一个简单的alert来检查jquery是否工作正常吗?此外,如果它的 jquery UI,使用 firebug 检查它是否在 ff 中加载正常!
-
@MarshallMathews:jQuery 工作正常,因为使用 $(document.createElement('div')).attr("id", dialogId) 初始化了 dialogDiv。我用萤火虫检查了这个。您将如何使用 Firebug 检查 jQuery-UI 是否可以正常加载?
-
console.log("This explains the dialog method: " + $.ui.dialog)如果为 false,则可能 UI 未正确加载 -
如果您使用的是 jQuery,为什么要使用
$(document.createElement('div')).attr("id", dialogId);创建一个 div?为什么不直接使用$('<div></div>').attr("id", dialogId);? -
从“/echo/html”加载时在 FF11 中工作正常。一定是代码中发生了其他事情。
标签: javascript jquery jquery-ui firefox jquery-ui-dialog