2017-01-20 6 views
1

変更」から「保存」にテキストボタンのテキストを変更します。JavaScript(ポリマー1.0)を使用して紙ボタンのテキストを変更

JavaScriptでこれを行うにはどうすればよいですか?

マイボタン

<paper-button id="msbutton" onclick="_changeText">Modify</paper-button> 

はJavaScript

Polymer({ 
    is: "test-button", 
    _changeText: function() { 
    var button = document.getElementById('msbutton'); 
    //What comes here? 
}) 

答えて

3

の中に#msbuttonは入っていますか?

あなたはPolymer's event binding syntaxon-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>

+0

@Vinod Louis Ya "onclick"が問題でした。それは今働く。ありがとう:-) – BlueCat

0

あなたが直接

この介してポリマーDOMセレクタを経由して使用することができます。$$( "#のmsbutton")。のinnerText = "保存";

+0

私は(私は初心者ごめんなさい)私は右のそれをやったのかはわからないが、私は私の機能を変更しました _changeText:function(){ this。$$( "#msbutton")。innerText = "保存"; } エラーが発生しました:**未キャッチのReferenceError:HTMLElement.onclickで_changeTextが定義されていません** 関数への参照に間違っていますか? – BlueCat

+1

がhtmlでオンタップ= "_ changeText"に設定されているかどうか教えてください –

+0

@BlueCatこのフィドルを参照してくださいhttps://jsfiddle.net/2q3fqehz/123/ –

関連する問題