Note: The checkbox in the HTML <input> tag class implements the single-selection effect.
In the recent development projects, customers require the use of small square lattice to achieve the "radio" function, it is clear that the DOT radio is out, can only choose the Chckbox block style, but also on the Internet, may be a bit of brain residue, not found.
Nonsense not much to say directly on the code:
<!DOCTYPE HTML> <HTMLxmlns= "http://www.w3.org/1999/xhtml"> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/> <title>checkbox for single-selection effects</title> <Scriptsrc= "Jquery-1.7.2.min.js"></Script> <Script>$ (document). Ready (function () { $('. SB'). Click (function () { varTypethis= typeof ($( This). attr ("checked")); Switch(typethis) { Case "string": if ($( This). attr ("checked"). toLowerCase ()=="checked") { $('. SB'). each (function () { $( This). Removeattr ("checked"); }); $( This). attr ("checked",true); } Break; Case "undefined": $('. SB'). each (function () { $( This). Removeattr ("checked"); }); Break; } }); }); </Script> </Head> <Body> <inputclass= "SB"type= "checkbox"value= "1"/> <inputclass= "SB"type= "checkbox"value= "2" /> <inputclass= "SB"type= "checkbox"value= "3" /> <inputclass= "SB"type= "checkbox"value= "4" /> </Body> </HTML>
Of course the code in case "undefined" is optional, you can try