jQuery IE 9 crash when replacing "tbody" value after clicking on an element inside it
I have an application in which I'd like a user action - checking on a checkbox - to cause a chain of actions that results, among other things, in the table in which the checkbox appears to be rewritten开发者_Python百科. This works fine in all browsers I've tested except IE 9.
I've reproduced the behavior in this jsfiddle: http://jsfiddle.net/vM7Bu/3/
but essentially the idea is
$('tbody#mytablebody').empty();
for (var i in something) {
$('tbody#mytablebody').append(makeNewRow(i));
}
Even in IE 9 this works fine unless it's triggered by a user clicking on something inside the current body of the table. In that case, IE goes into some kind of infinite loop.
Is this a known issue in IE 9? What workarounds might be available?
EDIT: I narrowed the problem down a little - it's not so much the sequence of events triggered from a click, but rather the fact that we're attempting to replace the innerHTML
of a tbody
(I think) when an element inside it has focus. Finding that element and blur
ing it seems to have helped somewhat. More investigation required.
Possible work-around. In the click handler, call setTimeout(xxx, 0); and do your work from the setTimeout function. If IE is crashing because you are removing parts of the table that you're in the middle of a click handler for, then the setTimeout will get you out of the click handler before remove that part of the table.
Pseudo-code:
$("#whatever").click(function() {
setTimeout(function() {
$('tbody#mytablebody').empty();
for (var i in something) {
$('tbody#mytablebody').append(makeNewRow(i));
}
}, 0);
});
As best I can tell, though I still have not managed to reproduce it without the use of jQuery, the issue is that in IE 9 you cannot remove certain kinds of elements from the DOM if those elements still have keyboard focus. That seems to be the rule. I will report it to MS if I can actually reproduce it in standalone code.
精彩评论