onclick在Chrome应用程序中不起作用?

时间:2016-12-14 09:37:49

标签: javascript android jquery ios

您好我正在创建一个Chrome应用。我使用java脚本在按钮上创建了一个click事件。它在简单的html页面中工作正常,但在chrome app中不起作用。



<!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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您无法在Chrome扩展程序中添加内联JavaScript。相反,您需要创建一个外部JavaScript文件,您可以在其中添加事件侦听器。像这样:

&#13;
&#13;
document.addEventListener('DOMContentLoaded', function() {
 document.getElementById('disable-button').addEventListener('click', function() {
        document.getElementById("btn01").disabled = true;
    });
});
&#13;
<!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>
&#13;
&#13;
&#13;