Aujourd'hui, quand je travaillais sur un projet, j'ai rencontré un problème. J'avais besoin d'afficher plusieurs cases à cocher à cocher à cocher, mais mais autorisé à sélectionner jusqu'à 6. Après le débogage pendant longtemps, il est finalement sorti, le code est le suivant:
<Script linguisse = "javascript"> var c = 0, limite = 6; fonction docheck (obj) {obj.checked? C ++: c--; if (c> limite) {obj.checked = false; alerte ("over"); C--; }} </ Script> <html> <body> <input type = "checkbox" name = "sampe1" onclick = "docheck (this)"> a <entrée type = "checkbox" name = "sampt 2" onclick = "docheck (this)"> b <entrée type = "checkbox" name = "sample3" onClick = "docheck (this)"> c <fort type = "name" name = "docheck (this)"> c <fant type = "name" name = "Docheck (this)"> C <fant type = "name" name = "DOCHECK (this)"> C <fant type = "Name" onclick = "docheck (this)"> d <input type = "checkbox" name = "sampe5" onclick = "docheck (this)"> e <input type = "checkbox" name = "sampe6" onclick = "docheck (this)"> f <entrée type = "checkbox" name = "samphle7" onclick = "Docheck (this)"> g <entrée type = "checkbox" name = "sampe8" "DOCHECK (this)"> g <entrée type = "Checkbox" onClick = "docheck (this)"> h <input type = "checkbox" name = "samptans9" onclick = "docheck (this)"> i <input type = "checkbox" name = "sampe10" onclick = "docheck (this)"> j </ body> </html>Les résultats de l'affichage sont les suivants: