复选框.checked
获取复选框的勾选状态
复选框.checked = true或者false
设置复选框的勾选状态
例:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <input type="checkbox" name="" id=""> <script> // 1. 获取元素 const ipt = document.querySelector('input') // 获取复选框的勾选状态 console.log(ipt.checked) // 设置复选框的勾选状态 ipt.checked = true console.log(ipt.checked) </script> </body> </html>