Javascript 如何访问聚合web组件中的输入元素

Javascript 如何访问聚合web组件中的输入元素,javascript,html,polymer,web-component,Javascript,Html,Polymer,Web Component,我已成功使用Polymer设置了一个简单的注册表: <polymer-element name="app-registration"> <template> <style> ... </style> <section> <paper-input class="username" .... ></paper-inpu

我已成功使用Polymer设置了一个简单的注册表:

<polymer-element name="app-registration">

    <template>
        <style>
            ...
        </style>
        <section>
            <paper-input class="username" .... ></paper-input>
            <paper-input class="password" .... ></paper-input>
            <paper-button label="Submit" on-tap="{{handleSubmit}}"></paper-button>
        </section>
    </template>

    <script>
        Polymer({
            handleSubmit: function (event, detail, sender) {
                alert(this.querySelector('.username').value);
            }
        });
    </script>

</polymer-element>

...
聚合物({
handleSubmit:函数(事件、详细信息、发送方){
警报(此.querySelector('.username').value);
}
});

但是,在
handleSubmit
回调中,我无法查询其他输入字段中的值。无论我查询的是
纸质输入
还是按类名接收的
null
。有什么建议吗?

这些元素都在您的影子dom中,因此您需要
this.shadowRoot
this.querySelector()
将为您提供轻型dom节点

this.shadowRoot.querySelector('.username').value
更好的方法是添加一个id:

<section id="container">
  <paper-input class="username" .... ></paper-input>
  ...
</section>

...

并使用节点查找:
this.$.container.querySelector(“.username”).value
这些元素都在您的影子dom中,因此您需要
this.shadowRoot
this.querySelector()
将为您提供轻型dom节点

this.shadowRoot.querySelector('.username').value
更好的方法是添加一个id:

<section id="container">
  <paper-input class="username" .... ></paper-input>
  ...
</section>

...

并使用节点查找:
this.$.container.querySelector(“.username”).value
这些元素都在您的影子dom中,因此您需要
this.shadowRoot
this.querySelector()
将为您提供轻型dom节点

this.shadowRoot.querySelector('.username').value
更好的方法是添加一个id:

<section id="container">
  <paper-input class="username" .... ></paper-input>
  ...
</section>

...

并使用节点查找:
this.$.container.querySelector(“.username”).value
这些元素都在您的影子dom中,因此您需要
this.shadowRoot
this.querySelector()
将为您提供轻型dom节点

this.shadowRoot.querySelector('.username').value
更好的方法是添加一个id:

<section id="container">
  <paper-input class="username" .... ></paper-input>
  ...
</section>

...

并使用节点查找:
this.$.container.querySelector(“.username”).value

不确定它是否已经在0.5中可用,但在1.0中可以使用

this.$$(selector)
你的例子是:

this.$$('.username').value
->相同但较短,适用于动态创建的节点


不确定它是否已经在0.5版中可用,但在1.0版中可以

this.$$(selector)
你的例子是:

this.$$('.username').value
->相同但较短,适用于动态创建的节点


不确定它是否已经在0.5版中可用,但在1.0版中可以

this.$$(selector)
你的例子是:

this.$$('.username').value
->相同但较短,适用于动态创建的节点


不确定它是否已经在0.5版中可用,但在1.0版中可以

this.$$(selector)
你的例子是:

this.$$('.username').value
->相同但较短,适用于动态创建的节点


或者,由于每个字段只有一个,因此设置
id=“username”
而不是
class=“username”
(密码也一样)。然后,您可以编写
这个.$.username.value
,而不需要
querySelector()
。或者,由于这些字段中只有一个字段,请设置
id=“username”
,而不是
class=“username”
(密码也一样)。然后,您可以编写
这个.$.username.value
,而不需要
querySelector()
。或者,由于这些字段中只有一个字段,请设置
id=“username”
,而不是
class=“username”
(密码也一样)。然后,您可以编写
这个.$.username.value
,而不需要
querySelector()
。或者,由于这些字段中只有一个字段,请设置
id=“username”
,而不是
class=“username”
(密码也一样)。然后您可以编写
this.$.username.value
,而不需要
querySelector()
。当没有dom repeat或dom if时,使用
id=“foo”
this.$.foo
。这更有效,因为它使用静态映射并且不查询dom。如果没有dom repeat或dom if,请使用
id=“foo”
This.$.foo
。这更有效,因为它使用静态映射并且不查询dom。如果没有dom repeat或dom if,请使用
id=“foo”
This.$.foo
。这更有效,因为它使用静态映射并且不查询dom。如果没有dom repeat或dom if,请使用
id=“foo”
This.$.foo
。这更有效,因为它使用静态映射,并且不查询dom。