2016-12-14 10 views
0

こんにちは私はクロームアプリを作成しています。私はボタンをJavaスクリプトを使用してクリックイベントを作成します。単純なhtmlページではうまく動作していますが、chromeアプリケーションでは動作しません。onclickはChromeのアプリで動作していませんか?

<!DOCTYPE html> 
 
<html> 
 
    <body> 
 
     <form> 
 
      <input type="button" id="btn01" value="OK"> 
 
     </form> 
 

 
     <p>Click the "Disable" button to disable the "OK" button:</p> 
 

 
     <button onclick="disableElement()">Disable</button> 
 

 
     <script> 
 
      function disableElement() { 
 
       document.getElementById("btn01").disabled = true; 
 
      } 
 
     </script> 
 
    </body> 
 
</html>

+0

私はonclickのイベントは、モバイル環境との互換性があるとは思いません。 –

+0

この投稿をチェックしましたか? http://stackoverflow.com/questions/13591983/onclick-within-chrome-extension-not-workingイベントリスナーを追加する必要があります。 –

答えて

0

あなたはChrome拡張機能でインラインJavaScriptを追加することはできません。代わりに、イベントリスナーを追加できる外部JavaScriptファイルを作成する必要があります。このような何か:

document.addEventListener('DOMContentLoaded', function() { 
 
document.getElementById('disable-button').addEventListener('click', function() { 
 
     document.getElementById("btn01").disabled = true; 
 
    }); 
 
});
<!DOCTYPE html> 
 
<html> 
 
<body> 
 
    <form> 
 
    <input type="button" id="btn01" value="OK"> 
 
    </form> 
 

 
    <p>Click the "Disable" button to disable the "OK" button:</p> 
 
    <button id="disable-button">Disable</button> 
 
</body> 
 
</html>

関連する問題