1.經常需要判斷某個按鈕是否被選中。
2.基於jquery。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>checked</title> </head> <body> <input id="box" type="checkbox" checked> <script src="./jquery-3.1.1.min.js"></script> <script> $("#box").on("click",function(){ // console.log($("#box").attr("checked")) if($(this).is(":checked")){ console.log("yes") } }) </script> </body> </html>