gpt4 book ai didi

javascript - Polymer 通过 javascript 纸质按钮

转载 作者:行者123 更新时间:2023-11-30 16:20:05 24 4
gpt4 key购买 nike

如何通过javascript实现一个 polymer 纸按钮?我正在尝试这样的事情。

var newPaperButtonElement = document.createElement('paper-button');
newPaperButtonElement.setAttribute('class','btn');
newPaperButtonElement.setAttribute('on-tap','{{ test}}');


var newCoreIconElement = document.createElement('core-icon');
newCoreIconElement.setAttribute('icon','remove-circle');
newCoreIconElement.setAttribute('class','icon');
newCoreIconElement.setAttribute('style', 'color: rgba(255, 0, 0, 0.42);')

newPaperButtonElement.appendChild(newCoreIconElement);

但是我的函数从未被调用过?什么都没发生。使用 polymer 0.5 atm...

最佳答案

您不能强制性地添加绑定(bind)。如果您命令式地创建元素,则必须命令式地添加/删除事件处理程序

newPaperButtonElement.addEventListener('tap', this.test);

test 可能需要根据函数所在的位置进行不同的查看(您的问题未提供上下文)。

我希望我的语法正确,我不使用 JS(仅使用 Dart)。

关于javascript - Polymer 通过 javascript 纸质按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34873661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com