jsp页面中select标签中怎么加checkbox实现多选?
使用JSP页面代码:
代码如下:
<table>
<tr>
<td width="400px" align="left">入学批次:<SELECT NAME="grade"
id="grade" onchange="refreshEduLevelAndSpecialAjax();"> //选择入学批次会刷新层次和专业
<OPTION VALUE="0">
--请选择--
<c:forEach items="${gradeInfo}" var="gradeInfo"州罩>
<OPTION VALUE="${gradeInfo.gradeName}">${gradeInfo.gradeName}
</c:forEach>
</SELECT></td>
<td width="400px" align="left">统考课程:<SELECT
NAME="uniExamCourseId" id="uniExamCourseId">
<OPTION VALUE="0">
--请选择--
<c:forEach items="${unifiedExamCourseList}" var="uniExamCourse">
<OPTION VALUE="${uniExamCourse.id}">${uniExamCourse.uniExamCourseName}
</c:forEach>
</SELECT></td>
</tr>
<tr>
<td colspan="2" id="refreshEduLevelAndSpecialAjax"> //设置ID,用于填充层次和专业的下拉框
<table>
<tr>
<td width="400" align="left">层 册返闹 次:<SELECT
NAME="eduLevelId" id="eduLevelId"
onchange="refreshSpecialAjax();"> //选择层次后刷新专业
<OPTION VALUE="0">--请选择--</OPTION>
<c:forEach items="${educationLevel}" var="educationLevel">
<OPTION VALUE="${educationLevel.id}">${educationLevel.educationLevelName}
</c:forEach>世散
</SELECT></td>
<td width="400" align="left" id="refreshSpecialAjax">专 业:<SELECT //设置ID,用于填充专业的下拉框
NAME="specialId" id="specialId">
<OPTION VALUE="0">--请选择--</OPTION>
<c:forEach items="${specialList}" var="special">
<OPTION VALUE="${special.id}">${special.specialName}
</c:forEach>
</SELECT></td>
</tr>
</table>
</td>
</tr>
</table>
代码如下:
<html>
<head>
<title>中国站长天空-网页特效-表单特效-下拉框中的复选框</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把下面代码加到<head>与</head>之间-->
<style type="text/css">
body,td{font-size:12px;color:#000000;}
.checkbox{width:15px;height:15px;}
.cked{margin:1px;padding:2px;width:98%;display:block;background-color:highlight;color:highlighttext;}
.nock{margin:1px;padding:2px;width:98%;display:block;}
</style>
</head>
<body>
<!--把下面代码加到<body>与团差</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];
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.getElementByIdx_x('l_"+name+"_"+i+"').className=(document.getElementByIdx_x('i_"+name+"塌悉皮_"+i+"').checked)?'cked':'nock';\" onclick=\"document.getElementByIdx_x('l_"+name+"_"+i+"').className=(document.getElementByIdx_x('i_"+name+"_"+i+"').checked)?'cked':'nock';\" type=\"checkbox\""+ck+" name=\""+name+"\" id=\"i_"+name+"_"+i+"\" value=\""+HtmlEncode(v)+"\" \/> ";
thisstr+=HtmlEncode(t)+"</label>";
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>
<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));'>get值</button></td>
</tr>
<tr>
<td><div style="width:180px;height:120px;overflow:auto;border: 2px inset #FFFFFF;">
<script language="javascript">
<!--
_checkbox("WebSite","Google.com@=http://www.google.com^Baidu.com@=http://www.baidu.com^Zzsky.cn@=http://www.zzsky.cn","http://www.zzsky.cn")
//-->
</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");'>set值</button>
<button onclick='alert(_getv(document.myform.WebSite));'>get值</button></td>
</tr>
<tr>
<td align="center"><button onclick='document.myform.reset();'>重置</button> </td>
</tr>
</table>
</form>
</body>
</html>