Select a specified number of checkbox not selectable (dimmed) JavaScript code _javascript Tips

Source: Internet
Author: User
Select 3 to see the effect
<script> function Disablecheckbox () {var obj=document.getelementsbytagname ("Input") for (Var i=0;i<obj.lengt h;i++) {if (!obj[i].checked) obj[i].disabled = true; The function Ablecheckbox () {var obj=document.getelementsbytagname ("Input") for (Var i=0;i<obj.length;i++) Obj[i]. disabled = false; function check () {var obj=document.getelementsbytagname ("input") var sun=0; for (Var i=0;i<obj.length;i++) {if (obj[i].type== "checkbox" && obj[i].checked) sun++; if (sun< 3) {ablecheckbox (); Break else if (Sun = 3) {Disablecheckbox (); Event.srcelement.checked=true; Break else if (Sun > 3) {event.srcelement.checked=false; Break }} </script> <input type= ' checkbox ' name= ' cate[] ' value= ' 102 ' onclick= ' Check (); " > Cantonese <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' "check ();" > Chaozhou <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' "check ();" > Hakka <input type= ' checkbox' Name= ' cate[] ' value= ' onclick= ' check (); > Sichuan <input type= ' checkbox ' name= ' cate[] ' value= ' ' onclick= ' "check ();" > Shanghai/Jiangsu <input type= ' checkbox ' name= ' cate[] ' value= ' ' onclick= ' check (); > Hunan <input type= ' checkbox ' name= ' cate[] ' value= ' 108 ' onclick= ' Check (); " > Hubei <input type= ' checkbox ' name= ' cate[] ' value= ' 109 ' onclick= ' check (); " > Guizhou <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' "check ();" > Northeast <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' check (); > Jiangxi <input type= ' checkbox ' name= ' cate[] ' value= ' 112 ' onclick= ' Check (); " > Beijing <input type= ' checkbox ' name= ' cate[] ' value= ' 113 ' onclick= ' check (); " > Shandong <input type= ' checkbox ' name= ' cate[] ' value= ' 114 ' onclick= ' Check (); > Taiwan <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' "check ();" > Xinjiang/Halal <input type= ' checkbox ' name= ' cate[] ' value= ' 116 ' onclick= ' Check (); " > Yunnan <input type= ' checkbox ' name= ' cate[] ' value= ' 117 ' onclick= ' Check ();"> Other Chinese Food <input type= ' checkbox ' name= ' cate[] ' value= ' 118 ' onclick= '" check (); " > Game <input type= ' checkbox ' name= ' cate[] ' value= ' 119 ' onclick= ' Check (); > hotpot <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' "check ();" > Seafood <input type= ' checkbox ' name= ' cate[] ' value= ' 121 ' onclick= ' "check ();" > Pisa <input type= ' checkbox ' name= ' cate[] ' value= ' 122 ' onclick= ' "check ();" > Buffet <input type= ' checkbox ' name= ' cate[] ' value= ' 123 ' onclick= ' Check (); " > Tea Restaurant <input type= ' checkbox ' name= ' cate[] ' value= ' 124 ' onclick= ' check (); > Snack Pasta <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' "check ();" > Barbecue <input type= ' checkbox ' name= ' cate[] ' value= ' 126 ' onclick= ' Check (); " > Vegetarian <input type= ' checkbox ' name= ' cate[] ' value= ' 127 ' onclick= ' Check (); " > Simple meal <input type= ' checkbox ' name= ' cate[] ' value= ' 128 ' onclick= ' Check (); > Fast food <input type= ' checkbox ' name= ' cate[] ' value= ' 129 ' onclick= ' check (); " > Bread Pastry <input type= ' checkbox ' Name= ' cate[] ' value= ' 130 ' onclick= ' check (); > Dessert <input type= ' checkbox ' name= ' cate[] ' value= ' 131 ' onclick= ' "check ();" > teahouse <input type= ' checkbox ' name= ' cate[] ' value= ' 132 ' onclick= ' check (); > Café <input type= ' checkbox ' name= ' cate[] ' value= ' ' onclick= ' "check ();" > Bar <input type= ' checkbox ' name= ' cate[] ' value= ' 134 ' onclick= ' Check (); " > Japan <input type= ' checkbox ' name= ' cate[] ' value= ' 135 ' onclick= ' check (); " > Korea <input type= ' checkbox ' name= ' cate[] ' value= ' 136 ' onclick= ' check (); " > Southeast Asia India <input type= ' checkbox ' name= ' cate[] ' value= ' 137 ' onclick= ' Check (); " > French <input type= ' checkbox ' name= ' cate[] ' value= ' 138 ' onclick= ' Check (); > Italian <input type= ' checkbox ' name= ' cate[] ' value= ' 139 ' onclick= ' Check (); > Latin <input type= ' checkbox ' name= ' cate[] ' value= ' 140 ' onclick= ' check (); > Borderless <input type= ' checkbox ' name= ' cate[] ' value= ' the ' onclick= ' () check (); > Western <input type= ' checkbox ' name= ' cate[] ' value= ' onclick= ' check (); > Other Western food
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.