首页 > html5 > 在Polymer中,为什么要使用`<input is =“iron-input”>`而不是`<iron-input>`?

在Polymer中,为什么要使用`<input is =“iron-input”>`而不是`<iron-input>`? (In Polymer, why use `<input is=“iron-input”>` instead of `<iron-input>`?)

问题

在Polymer文档(https://elements.polymer-project.org/elements/iron-input)中,我发现:

<input is="iron-input" bind-value="{{myValue}}">

在另一份官方文件(https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html#type-extension)中,我发现:

    <dom-module id="main-document-element">
      <template>
        <p>
          Hi! I'm a Polymer element that was defined in the
          main document!
        </p>
      </template>
      <script>
        HTMLImports.whenReady(function () {
          Polymer({
            is: 'main-document-element'
          });
        });
      </script>
    </dom-module>
    <main-document-element></main-document-element>

我只是想知道为什么第一个<input is="iron-input" bind-value="{{myValue}}">不能写成<iron-input bind-value="{{myValue}}">

它是否兼容,这使得更容易填充?

解决方法

iron-input元素的源代码中不包含任何HTML。这意味着:

<iron-input bind-value="{{myValue}}">

不会在页面上产生实际输入以供用户与之交互。该iron-input元素实际上是可以应用于标准HTML输入的行为集合。

问题

In the Polymer document (https://elements.polymer-project.org/elements/iron-input), I found:

<input is="iron-input" bind-value="{{myValue}}">

And in another official document (https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html#type-extension) , I found:

    <dom-module id="main-document-element">
      <template>
        <p>
          Hi! I'm a Polymer element that was defined in the
          main document!
        </p>
      </template>
      <script>
        HTMLImports.whenReady(function () {
          Polymer({
            is: 'main-document-element'
          });
        });
      </script>
    </dom-module>
    <main-document-element></main-document-element>

I was just wondering why the first one <input is="iron-input" bind-value="{{myValue}}"> can't be written as <iron-input bind-value="{{myValue}}">.

Is it for compatibility, which makes it easier to polyfill?

解决方法

The iron-input element does not contain any HTML in its source code. This means that doing:

<iron-input bind-value="{{myValue}}">

will not produce an actual input on the page for the user to interact with. The iron-input element is really a collection of behaviours that you can apply to a standard HTML input.

相似信息