2016-06-14 73 views
0

我想达到什么:访问DOM

  1. 亮点在p元素一些文本

  2. (未添加/或删除)纸徽章时值为0

  3. 根据编号改变纸张徽章颜色

使用示例模块:

<link rel="import" href="https://polygit2.appspot.com/components/polymer/polymer.html"> 
<link rel="import" href="https://polygit2.appspot.com/components/iron-icons/communication-icons.html"> 
<link rel="import" href="https://polygit2.appspot.com/components/paper-icon-button/paper-icon-button.html"> 
<link rel="import" href="https://polygit2.appspot.com/components/paper-badge/paper-badge.html"> 

<dom-module id="question-one"> 
    <template> 
     <template is="dom-repeat" items="{{numbers}}"> 
      <p>color one of my letters</p> 
      <paper-icon-button id="someid{{index}}" icon="communication:email"></paper-icon-button> 
      <paper-badge for="someid{{index}}" label="{{item}}"> </paper-badge> 
     </template> 
    </template> 
    <script> 
     Polymer({ 
      is: "question-one", 
      properties: { 
       numbers: { 
        type: Array, 
        value: function() { 
         return [0, 1, 2, 0, 4, 5, 0, 7, 8, 0] 
        } 
       } 
      } 
     }); </script> 
</dom-module> 

与用法:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <script src="https://polygit2.appspot.com/components/webcomponentsjs/webcomponents-lite.js"></script> 
    <link rel="import" href="questions//question-one.html" /> 
</head> 
<body> 
    <question-one></question-one> 
</body> 
</html> 
+0

作为参考,与DOM的记录在这里:HTTPS://www.polymer-project。组织/ 1.0 /文档/ devguide /本地-DOM#DOM的API –

回答

2

添加id属性

<p id="someId"> 

使用$地图获得参考元素

this.$.someId.innerText... 

this.$不适用于动态添加的HTML或HTML内部template is="dom-if" or template is =“dom-repeat”或类似内容。

对于这样的情况下,你可以使用this.$$(selector)所有CSS选择器都支持,而this.$...只支持id(不含#