[英]Send message to background.js from options.js in Chrome Extension
[英]Event listener not firing off in options.js in chrome extension
在我的選項頁面中,在我的 chrome 擴展程序中,我想在用戶輸入其值並單擊提交按鈕時讀取用戶輸入。
選項.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: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>
選項.js
...
document.getElementById("button1").addEventListener("change", function(e) {
var day = document.getElementById("day").value; // get the current value of the input field.
alert(day);
});
您正在聆聽change
而不是click
。
addEventListener("click", function(){})
您目前僅在按鈕值更改時運行您的函數(並且由於按鈕沒有值,因此永遠不會觸發)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.