简体   繁体   English

重新呈现视图后,event.currentTarget.innerHTML在IE10中为空

[英]event.currentTarget.innerHTML is empty in IE10 after view is re-rendered

Here is the JSBin Demo (Please test in Chrome and IE10 to see the difference) 这是JSBin演示 (请在Chrome和IE10中测试以查看区别)

HTML HTML

<body>
  <div id='a'>
    <button>CLick me</button>
  </div>
</body>

JS JS

var markup = '<button>CLick me</button>';

$('#a').on('click', 'button', function() {
  $('#a').html(markup);
});

$('#a').on('click', 'button', function(event) {
  console.log(event.currentTarget.innerHTML); //.....(1)
});

Line (1) gives correct output in Chrome and Firefox while in IE10 I get empty string as the value of event.currentTarget.innerHTML . 第(1)行在Chrome和Firefox中提供正确的输出,而在IE10中,我得到空字符串作为event.currentTarget.innerHTML的值。 It only happens when div(#a) is rendered again. 它只会在div(#a)再次渲染时发生。

PS: I am using Backbone.js in which I re-rendered the view but to make question simpler, I have refined the problem to above mentioned by taking backbone out of picture. PS:我正在使用Backbone.js ,其中我重新渲染了视图,但为了使问题更简单,我已经通过将骨干取出图片来改进上面提到的问题。

I was curious so had a go. 我很好奇,所以有一个去。 This won't answer your question but might point in the right direction 这不会回答你的问题,但可能指向正确的方向

(1) In your example you replace a button with an identical button, if you replace it with different text you'll see in chrome that the innerHTML is actually the unreplaced text (1)在你的例子中,你用一个相同的按钮替换一个按钮,如果你用不同的文本替换它,你会在chrome中看到innerHTML实际上是未替换的文本

(2) In IE currentTarget is an empty button with no parent (2)在IE中, currentTarget是一个没有父项的空按钮

(3) It (sort of) works in IE and chrome if you do this: (3)如果你这样做,它(有点)适用于IE和chrome:

event.delegateTarget.children[0].innerHTML

(4) doc type makes no difference either way (4)doc类型无论如何都没有区别

So your answer will be in finding the difference between delegateTarget and currentTarget, or just using delegateTarget 所以你的答案是找到delegateTarget和currentTarget之间的区别,或者只是使用delegateTarget

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM