簡體   English   中英

事件偵聽器未在 chrome 擴展中的 options.js 中觸發

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM