jquery IE8 / 9/10绑定点击不起作用
问题描述:
面对IE和jquery的问题。该代码适用于所有其他浏览器,但在IE中使用时会中断。相当简单的实施。但我是javascript新手。
Facing an issue with IE and jquery. The code is working in all other browsers but breaks when used in IE. Fairly simple implementation. But I am javascript novice.
console.log('hi ie');
jQuery(document).ready(function () {
setTimeout(function () {
jQuery(".controlApply").on("click", function (event) {
pollVisibility();
console.log('after poll');
});
}, 1000);
});
//This method checks is a specific div is shown. Dirty way to check if a report is being processed
function pollVisibility() {
console.log('poll');
if (microstrategy.bones.rwb_viewer.objectID == '7647F4F611E2B39B923E0080EF058C78') {
if (!jQuery('#divWaitBox').attr('style')) {
console.log('divWaitBox');
//wait did not appear
microstrategy.getViewerBone().commands.exec('refresh');
} else if (jQuery('#divWaitBox').attr('style').indexOf('hidden') != -1) {
console.log('hidden');
microstrategy.getViewerBone().commands.exec('refresh');
} else {
console.log('other');
setTimeout(pollVisibility, 800);
}
} else {}
}
控制台。 log永远不会被调用但是document.ready似乎在IE中工作
The console.log never is called however the document.ready seems to work in IE
doctype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
如果错了,我无法改变它。这是MicroStrategy BI应用程序的扩展。
If its wrong, I cannot change it. This is an extension of the MicroStrategy BI application.
答
根据您的jQuery版本,您的问题可能是 .bind()
应使用 .on()
执行此类
Depending on your jQuery version, your issue is likely the .bind()
which should be performed with .on()
like this
HTML
<div class="class" style="height:40px; width:40px; background-color:#ff0000;"></div>
jQuery
$(document).ready(function () {
$(".class").on("click", function (event) {
console.log('We clicked!');
poll(); // <-- wtf does this do exactly??
});
});