中文(繁体)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>帶複選框的列錶框- 51windows.Net </title> <meta http-equiv ="內容類型" content="text/html; charset=gb2312"> </head> <style> body,td{font-size:12px;color:#000000;} .checkbox{width:15px;height:15px ; } .cked{ margin:1px;padding:2px;width:100%;display:block;background-color:highlight;color:highlighttext; } .nock{ 邊距:1px;填充:2px;寬度:100%;顯示:塊; } </style> <body> <SCRIPT LANGUAGE="JavaScript"> <!-- function HtmlEncode(text){ return text.replace(/&/g, '&').replace(/"/g, ' ”').replace(/</g, '<').replace(/>/g, '>'); } function _checkbox(name,str,defv){ //haiwa@2005-8-17 / / http://www.51windows.net var arr=str.split("^"); var ck="",bc=""; for(var i=0;i<arr.length;i++){ var thisarr =arr[i].split("@="); if (thisarr[0].length>0){ var t=(thisarr.length==2)?thisarr[0]:arr[i]; v= (thisarr.length==2)?thisarr[1]:arr[i]; if((","+HtmlEncode(defv).toLowerCase()+",").replace(/ ,/g, ' ,' ).indexOf(","+v+",")!=-1){ck="checked";cls="cked";} else{ck="";cls="nock";} var thisstr =" <標籤類別=""+cls+"" for="i_"+name+"_"+i+"" id="l_"+name+"_"+i+"">" thisstr+ ="<輸入類別="複選框" onpropertychange="document.getElementById('l_"+name+"_"+i+"').className=(document.getElementById('i_"+name+"_"+i+ " ').checked)?'cked':'nock';" onclick="document.getElementById('l_"+name+"_"+i+"').className=(document.getElementById('i_"+ name+ "_"+i+"').checked)?'cked':'nock';" type="checkbox""+ck+" name=""+name+"" id="i_" + name+"_"+i+"" value=""+HtmlEncode(v)+"" /> "; thisstr+=HtmlEncode(t)+"</label>";文檔.write(thisstr); } } } function _getv(o){ var allvalue=""; if(typeof(o)=="未定義"){return "";} if (typeof(o.length)=="未定義"){ if(o.checked){return o.value+ ","; }else {return "";} } for(var i=0;i<o.length;i++){ if(o[i].checked){ allvalue +=o[i].value+",";傳回所有值; } function _setv(o,defv){ var allvalue=(","+HtmlEncode(defv).toLowerCase()+",").replace(/ ,/g, ','); for(var i=0;i<o.length;i++){ var v = o[i].value; o[i].checked=(allvalue.indexOf(","+v+",")!=-1) } return allvalue; } function _sl(o,b){ for(var i=0;i<o.length;i++){ o[i].checked = b //if(o[i].checked!=b){o[ i].click();} } } //--> </SCRIPT> <form method="post" name="myform" action="?"> <table border="0" width="200"> <tr> <td><div style="width:180px;height:150px;overflow:auto;border: 2px inset #FFFFFF;"> <SCRIPT LANGUAGE="JavaScript"> <!-- _checkbox("city",北京^山東^安徽^重慶^福建^甘肅^廣東^廣西^貴州^海南^河北^黑龍江^河南^湖北^湖南^內蒙古^江蘇^江西^吉林^遼寧^寧夏^青海^山西^陝西^上海^四川^天津^西藏^新疆^雲南^浙江^香港^澳門^台灣","北京,山東") //--> </SCRIPT></div> </td> </tr> <tr> < td> <button onclick='_sl(document.myform.city,true);'>全選</button> <button onclick='_sl(document.myform.city,false);'>全選</ Button> <button onclick='_setv(document.myform.city,"甘肅,廣東");'>set值</button> <button onclick='alert(_getv(document.myform.city));'>取得值< /button> </td> </tr> <tr> <td><div style="width:180px;height:120px;overflow:auto;border: 2px inset #FFFFFF;"> <SCRIPT LANGUAGE=" JavaScript" > <!-- _checkbox("網站","Google.com@=http://www.google.com^downcodes.com@=http://www.downcodes.com^51windows.Net@=http :/ /www.downcodes.net","http://www.downcodes.net") //--> </SCRIPT></div> </td> </tr> <tr> <td> < Button onclick ='_sl(document.myform.WebSite,true);'>全選</button> <button onclick='_sl(document.myform.WebSite,false);'>全選</button> <button onclick=' _setv(document.myform.WebSite,"http://www.google.com");'>設定值</button> <button onclick='alert(_getv(document.myform.WebSite));' >get值</button> </td> </tr> <tr> <tdalign="center"><button onclick='document.myform.reset();'>重設表單</button> </ td> </ tr> </table> </form> </body> </html>