<div class="htmlarea"><textarea id="runcode7105"> <title>带Checkbox的列表框 - 51windows.Net </title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <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{ margin:1px;padding:2px;width:100%;display:block; } </style> <script language="JavaScript"> <!-- function HtmlEncode(text){ return text.replace(/&/g, '&').replace(/\"/g, '"').replace(/, '<').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]; var 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="<label class=\""+cls+"\" for=\"i_"+name+"_"+i+"\" id=\"l_"+name+"_"+i+"\">"; thisstr+="<input class=\"checkbox\" 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)+""; document.write(thisstr); } } } function _getv(o){ var allvalue=""; if(typeof(o)=="undefined"){return "";} if (typeof(o.length)=="undefined"){ if(o.checked){return o.value+ ",";}else{return "";} } for(var i=0;i<o.length;i++){ if(o[i].checked){ allvalue +=o[i].value+","; } } return allvalue; } 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> </table> </form></textarea></div>