[英]Change the text of a paper-button with JavaScript (polymer 1.0)
I want to change the text of a paper-button from " Modify " to " Save ". 我想将纸质按钮的文本从“ 修改 ” 更改为“ 保存 ”。
How can I achieve this with JavaScript? 如何使用JavaScript实现呢?
My Button 我的按钮
<paper-button id="msbutton" onclick="_changeText">Modify</paper-button>
JavaScript JavaScript的
Polymer({
is: "test-button",
_changeText: function() {
var button = document.getElementById('msbutton');
//What comes here?
})
Is the #msbutton
inside your test-button
element? #msbutton
是否在test-button
元素中?
You should use Polymer's event binding syntax ( on-click
not onclick
): 您应该使用Polymer的事件绑定语法 (
on-click
而非onclick
):
Polymer({ is: "test-button", _changeText: function() { var button = this.$.msbutton; button.textContent = 'new text'; } });
<base href="http://polygit.org/components/"> <link href="polymer/polymer.html" rel="import"> <link href="paper-button/paper-button.html" rel="import"> <test-button></test-button> <dom-module id="test-button"> <template> <paper-button id="msbutton" on-click="_changeText">Modify</paper-button> </template> </dom-module>
You can directly use via polymer dom selector via 您可以通过聚合物dom选择器直接通过
this.$$("#msbutton").innerText = "Save"; this。$$(“#msbutton”)。innerText =“保存”;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.