Vor kurzem habe ich auf ein kleines Problem gestoßen. Manchmal, wenn wir Radio mit einem Wahl verwenden, werden wir feststellen, dass wir bei einer Auswahl nicht mehr eine auswählen können, dh nach der Auswahl gibt es keine Stornierungsfunktion. Zu diesem Zeitpunkt denken wir an das leistungsstarke Kontrollkästchen, aber es ist Multiple Choice. Wie können wir es zu einer einzigen Wahl machen? Der Effekt ist der gleiche wie Radio. Dieser Rookie schrieb ein kleines Programm alleine. Der Code ist sehr einfach mit nur vier Zeilen.
Direkter Code ohne weiteres:
Die Codekopie lautet wie folgt:
<! DocType html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transsitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<kopf>
<meta http-äquiv = "content-type" content = "text /html; charset = utf-8" />
<script src = "js/jquery-1.8.3.min.js" type = "text/javaScript" Sprache = "JavaScript"> </script>
<title> bis zum Titel "Dokument" </title>
<script type = "text/javaScript">
$ (function () {
$ (": checkbox"). click (function () {
if ($ (this) .attr ("geprüft")! = undefiniert)
{
$ (this) .Siblings (). Attr ("geprüft", falsch);
$ (this) .attr ("geprüft", wahr);
}
});
});
</script>
<Styles>
Span, Eingabe {float: links;}
Eingabe {Breite: 14px; Höhe: 14px;}
Span {Margin-Right: 20px;}
</style>
</head>
<body>
<div>
<input type = "checkbox" /> <span> 1 < /span>
<Eingabe type = "checkBox" /> <span> 2 < /span>
<Eingabe type = "checkBox" /> <span> 3 < /span>
<input type = "checkbox" /> <span> 4 < /span>
<input type = "checkBox" /> <span> 5 < /span>
<Eingabe type = "checkBox" /> <span> 6 < /span>
<Eingabe type = "text" /> <span> 7 < /span>
</div>
</body>
</html>