当利用for loop为若干个radio input元素添加eventlistener的时候并未生效,错误提示为:Uncaught TypeError: value.addEventListener is not a function。请问这是为什么?
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <div class="size_radio1">
- <input type="radio" name="radio1" id="50" data-add="100">50cm
- <input type="radio" name="radio1" id="75" data-add="200">75cm
- <input type="radio" name="radio1" id="100" data-add="300">100cm
- <input type="radio" name="radio1" id="150" data-add="400">150cm
- <input type="radio" name="radio1" id="225" data-add="500">225cm
- </div>
- </body>
- <script>
- let value1 = document.querySelector(".size_radio1");
- let cm_values = value1.querySelectorAll("input");
-
- function cm_se(){
- console.log("Yay!");
- }
-
- for (let value in cm_values){
- value.addEventListener("click",cm_se);
- }
- </script>
- </html>
-