从 vanilla JS 获取 paper-listbox 的价值
Get value of paper-listbox from vanilla JS
由于 MDL 不提供 select 元素,我决定结合使用 paper-dropdown-menu 和 paper-listbox 来获得所需的结果。现在,如果用户选择一个选项并按下一个按钮,我想从原版 JavaScript 中读取所选值(jQuery 也是可能的)。
更具体地说:如果它是一个普通的文本字段,我会这样做
var user_input = $('#text-input-field').val()
聚合物元素有类似的东西吗?
如果可能的话,我想避免编写自己的 web 组件。
干杯
标准 DOM 方法似乎工作正常时,您是否遇到了特殊问题?
// Define the class for a new element called custom-element
class CustomElement extends Polymer.Element {
static get is() {
return 'custom-element';
}
constructor() {
super();
this.value = 'The value.';
this.textContent = 'I\'m a custom-element.';
}
}
// Register the new element with the browser
customElements.define(CustomElement.is, CustomElement);
const custom = document.querySelector('custom-element');
console.log(custom.value);
<link rel="import" href="https://polygit.org/polymer+2.0.0-rc.2/components/polymer/polymer-element.html">
<custom-element />
由于 MDL 不提供 select 元素,我决定结合使用 paper-dropdown-menu 和 paper-listbox 来获得所需的结果。现在,如果用户选择一个选项并按下一个按钮,我想从原版 JavaScript 中读取所选值(jQuery 也是可能的)。
更具体地说:如果它是一个普通的文本字段,我会这样做
var user_input = $('#text-input-field').val()
聚合物元素有类似的东西吗?
如果可能的话,我想避免编写自己的 web 组件。
干杯
标准 DOM 方法似乎工作正常时,您是否遇到了特殊问题?
// Define the class for a new element called custom-element
class CustomElement extends Polymer.Element {
static get is() {
return 'custom-element';
}
constructor() {
super();
this.value = 'The value.';
this.textContent = 'I\'m a custom-element.';
}
}
// Register the new element with the browser
customElements.define(CustomElement.is, CustomElement);
const custom = document.querySelector('custom-element');
console.log(custom.value);
<link rel="import" href="https://polygit.org/polymer+2.0.0-rc.2/components/polymer/polymer-element.html">
<custom-element />