Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发展铬延伸_Javascript_Html_Google Chrome_Browser Extension - Fatal编程技术网

Javascript 发展铬延伸

Javascript 发展铬延伸,javascript,html,google-chrome,browser-extension,Javascript,Html,Google Chrome,Browser Extension,我是开发chrome扩展的初学者,我在popup.html文件中编写了以下代码,该文件链接到扩展的browser\u action的default\u popup <!DOCTYPE html> <html> <head> <script type="text/javascript" > function returnname() { var x=document.getElementById("name"

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

  <!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>

函数returnname()
{
var x=document.getElementById(“名称”).value;
警报(x);
};
用户名:

密码:


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

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

使用addEventListener或使用jQuery。使用“单击此处”按钮

$().click(function(){

});