3

我是开发 chrome 扩展的初学者,我在我的扩展链接到的popup.html文件中编写了以下代码default_popupbrowser_action

  <!DOCTYPE html>
  <html>
  <head>
  <script  type="text/javascript" >
  function returnname()
  {
        var x=document.getElementById("name").value;

        alert(x);
  };
  </script>
  </head>
  <body>

  <p>Username : <input type="text"  id="name" height="20" width="50" />
  </p>
  <p>Password : <input type="password"  id="password" height="20" width="50" />
  </p>

  <input type="button" name="submit" onclick="returnname()" value="login"></input>
  <textarea id="return_name" rows="2" columns="20"></textarea>

  </body>
  </html>

但是,每当我单击登录按钮时,javascript 没有像 in 那样运行,它不会显示任何警报消息。我在这里错过了什么?

4

1 回答 1

0

您应该尝试绑定您的代码,并避免在您的 chrome 扩展上使用 onclick,因为它在最新的 chrome 版本上不再有效。

使用 addEventListener 或者如果你使用 jQuery。使用那里的点击

$().click(function(){

});

http://www.html5rocks.com/en/tutorials/security/content-security-policy/#inline-code-considered-harmful

于 2012-12-20T08:49:59.223 回答