Javascript 事件侦听器未在chrome扩展的options.js中启动
在我的选项页面中,在我的chrome扩展中,我想在用户输入值并单击提交按钮时读取用户输入 options.htmlJavascript 事件侦听器未在chrome扩展的options.js中启动,javascript,jquery,google-chrome,google-chrome-extension,Javascript,Jquery,Google Chrome,Google Chrome Extension,在我的选项页面中,在我的chrome扩展中,我想在用户输入值并单击提交按钮时读取用户输入 options.html <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> </head> <body> <h1 style="font-family:Ralewa
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body>
<h1 style="font-family:Raleway;font-weight:200;text-align:center;font-size:50px;color:white;">Themes</h1>
<input type="number" id="day" value="2" class="day">
<button id = "button1">Submit</button>
<script src="options.js"></script>
</body>
</html>
您正在收听的是
更改
而不是单击
addEventListener(“单击”,函数(){})
您当前仅在按钮值更改时运行功能(由于按钮没有值,因此永远不会触发)我已更新了我的options.js,但它仍然没有发出警报。谢谢不要通过编辑使现有答案无效。如果您仍然有问题,请提出新问题或对答案进行评论。好的,对不起。因为下面的答案,我改变了它。我现在不这样做。再一次,对不起!更改后是否重新加载扩展?因为Chrome缓存了所有的JS。@Xan是的,我只是在代码中更改了
addEventListener(“单击”,function(){
)。我的意思是重新加载整个扩展,而不仅仅是选项页面。
...
document.getElementById("button1").addEventListener("change", function(e) {
var day = document.getElementById("day").value; // get the current value of the input field.
alert(day);
});