javascript - <demo-snippet> 内的元素仅在 IE11 中无法正确克隆/投影

标签 javascript polymer polymer-1.0

我认为该元素在 IE11 中没有正确投影。看下面的例子:

<body unresolved>

  <p>If this demo works correctly, you should be able to see the message <code>"Hello there. Hola!"</code></p>

  <p>
    This works as expected in all browsers except Internet Explorer 11 (maybe 10, although I didn't test). The issue is that when I assign helloElement.value, helloElement is not the same element that is being appended to the dome after is projected inside
    the &lt;demo-snippet&gt;.
  </p>

  <demo-snippet>
    <template is="dom-bind">
      <hello-element></hello-element>

      <script>
        var helloElement = document.querySelector('hello-element');
        helloElement.value = 'Hola!';

        // Wait enough time to make sure demo-snipper is rendered properly
        setTimeout(function() {
          console.log(helloElement === document.querySelector('hello-element')) // this is true in all browsers. In IE11 is false.
        }, 3000)
      </script>
    </template>

  </demo-snippet>
</body>

所发生的情况是,在除 IE11 之外的所有浏览器中,helloElement.value 中分配的值都会被复制到 demo-snippet 元素内的投影元素中。这意味着,如果您添加一个就绪的处理程序并且您这样做

ready: function () {
   console.log(this.value) // --> 'Hola!' except IE11, that is ''
}

将我的代码投影到其中时,这是 Polymer 或 demo-snippet 中的错误吗?或者什么时候附加到dom?我真的不知道:(

您可以在这个 Plunker 中使用我的示例:https://plnkr.co/edit/5UBCDjqC0A8k6HcaHnIJ?p=preview

最佳答案

显然 IE 对此更加严格。您需要调用 element.setAttribute 而不是仅仅将其添加到对象中。

这将确保 polymer 选择默认值作为属性。

关于javascript - <demo-snippet> 内的元素仅在 IE11 中无法正确克隆/投影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39915765/

相关文章:

javascript - Polymer 3 ide - 模板编辑

javascript - 获取模板内单选按钮的值

Polymer 1.0 纸菜单按钮 horizo​​ntalAlign 和 horizo​​ntalOffset 不起作用

Polymer 1.0 - 数据绑定(bind)数组未正确更新

javascript - 使用 ExtJS TabPanel 的选项卡标题显示所需符号的好方法是什么?

javascript - 模板文字在 JavaScript 中无法正常工作

javascript - 如何将相同的 css 类添加到 polymer 中的所有自定义元素。

polymer-1.0 - 进行了 Polymer 1.0 iron-ajax 调用,但响应未触发且数据未绑定(bind)

javascript - 如何在 webpack 中导入的 html 文件中使用从 index.js 导入的样式?

使用 JSON 对象将 PHP 数组转换为 JavaScript - 返回 null