【问题标题】:Get raw HTML code of polymer elements获取聚合物元素的原始 HTML 代码
【发布时间】:2016-02-18 15:09:05
【问题描述】:

让我解释一下情况:

在 div(#content) 中有一个纸张输入。现在我想在我使用$("#content").html() 的 div#content 中获取 html 代码。

但是$("#content").html() 给了我聚合物注入的代码。

例子:

$("#content").html() 的预期输出为:

         <paper-input label="text input"></paper-input>

但是是给我以下结果:

     <paper-input label="text input" tabindex="0" aria-disabled="false" class="x-scope paper-input-0">
       <paper-input-container class="style-scope paper-input x-scope paper-input-container-0">
        ....
        <template is="dom-if" class="style-scope paper-input-container"></template>
        ....
        ...
     </paper-input>

有没有铁元素可以获取原始html代码。

【问题讨论】:

    标签: javascript polymer polymer-1.0


    【解决方案1】:

    $("#content").html() 的预期输出是正确的,因为聚合物创建的那些节点现在属于 DOM。

    如果由于某种原因您需要在不更改原始元素的情况下创建的元素的原始 html,您可以随时克隆它,清除它的子元素并删除由聚合物创建的属性

    var cln = $('#content paper-input').clone().html('')[0];
    cln.removeAttribute('tabindex');
    cln.removeAttribute('class');
    cln.removeAttribute('aria-disabled');
    console.log(cln.outerHTML);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多