Javascript 发展铬延伸
我是开发chrome扩展的初学者,我在popup.html文件中编写了以下代码,该文件链接到扩展的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"
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(){
});