自身身上的开关思想
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <input onclick='pdF(this)' type="checkbox" style='width:16px;' checked="checked" /> <input onclick='pdF(this)' type="checkbox" style='width:16px;' checked="checked" /> </body> <script type="text/javascript"> //方法一 // function pdF(data){ // if(data.getAttribute("checked")){ // console.log("被取消") // data.removeAttribute("checked") // }else{ // data.setAttribute("checked","true") // console.log("被选中") // } // } // 方法二 function pdF(data){ if(data.checked){ console.log("被选中") }else{ console.log("被取消") } } </script> </html>