这个在程序中会经常用到。以前的程序都是使用后台代码来获得用户的选择项,在客户端,可以使用JavaScript来做这个判断,减轻服务器端的负担。 < html > < head > < script language = " JavaScript " type = " text/javascript " > function btn_Check_onclick() ... { var myElement; var numberOfControls=document.form1.length; var compSpec="Your chosen language is "; for(var i=0;i<numberOfControls;i++) ...{ myElement=document.form1[i]; if(myElement.type=="checkbox") ...{ if(myElement.checked==true) ...{ compSpec+=myElement.value+" "; } } } alert(compSpec);} </ script > </ head > < body > < form name = " form1 " > < div > < h1 > Please choice your language: </ h1 > < br /> < p > < table > < tr > < td > Java </ td > < td >< input type = " checkbox " name = " chk_Java " value = " Java " ></ td > </ tr > < tr > < td > C# </ td > < td >< input type = " checkbox " name = " chk_c# " value = " cSharp " ></ td > </ tr > < tr > < td > Python </ td > < td >< input type = " checkbox " name = " chk_Python " value = " Python " ></ td > </ tr > < tr > < td >< input type = " button " name = " btn_Check " value = " Sub_Check " onclick = " return btn_Check_onclick() " ></ td > </ tr > </ table > </ p > </ div > </ form > </ body > </ html >