【发布时间】:2013-05-19 16:53:08
【问题描述】:
下面是一个更大项目的一部分(显然),它在 Chrome、Firefox 和 Opera 中运行良好,但 .click() 函数没有被 IE9 或 10 调用。
jQuery('.current img').hover(function() {
var thisElem = jQuery(this);
thisElem.parent().parent().find('.hotspot span:not(.select-image)').remove();
thisElem.parent().parent().find('.hotspot img').parent().find('span.select-image').remove();
jQuery('<span class="zoom-out"></span>').prependTo(thisElem.parent()).click(function() {
z -= .1;
z = Math.max(z, 1);
jQuery(this).parent().find('img').attr('src', '<?php echo $urlPrefix; ?>/zcard-thumbnail-image/photos/<?php echo $modelId; ?>/low/' + i + '/' + (w * z) + '/' + (h * z) + '/file');
});
jQuery('<span class="select-image"></span>').prependTo(thisElem.parent());
jQuery('<span class="zoom-in"></span>').prependTo(thisElem.parent()).click(function() {
z += .1;
z = Math.min(z, 5);
jQuery(this).parent().find('img').attr('src', '<?php echo $urlPrefix; ?>/zcard-thumbnail-image/photos/<?php echo $modelId; ?>/low/' + i + '/' + (w * z) + '/' + (h * z) + '/file');
});
});
据我所知,.click() 没有绑定,因为元素还不存在。如果我改为使用 jQuery(target).prepend(element),然后发出延迟进一步执行的警报,然后 .click() 绑定,一切正常。不幸的是,用 delay() 替换警报不会产生相同的结果。
请问大家有什么建议吗?
【问题讨论】:
-
你当然在某处声明了
z、h和w? -
哈,我做到了 =)。这一切都在其他浏览器中完美运行,如果我使用警报来导致创建元素和添加绑定之间的延迟,那么一切在 IE9/10 中也能正常运行。好像 IE 在更新 DOM 时太慢了,无法在创建后立即附加绑定。
-
这是一个更旧的版本,但同样的问题似乎出现在这个问题上(我现在正在尝试调试的系统的一部分的模拟、线框构建,恐怕我无法提供访问):development.qweb.co.uk/tim-bailey/zcard
标签: jquery internet-explorer-9 internet-explorer-10