日期:2014-05-20  浏览次数:20691 次

SSH 循环checkbox,判断是否被选中。怎么写?
<logic:present name="allpurview" scope="request">
<logic:iterate id="purview" name="allpurview" scope="request">
${purview.purviewname}<html:checkbox property="purview" value="${purview.id}"></html:checkbox>
</logic:iterate>
</logic:present>

以上是输出所有的。 现在想要的效果是,若 ${adminpower.purview}的值比如是1,跟其中某个checkbox相同,则checkbox选中。

怎么写!

------解决方案--------------------
就跟你写Java代码类似的嘛,判断下输出的结果,也就是判断下条件是否成立。给你看个JSTL标签示例
HTML code

<c:choose>
  <c:when test=”${adminpower.purview=1}”>
     <input type="checkbox" name="..." value="..." checked></input>选中
     </c:when>
   <c:otherwise>
     <input type="checkbox" name="..." value="..." ></input>不选中
   </c:otherwise>
</c:choose>

------解决方案--------------------
个人感觉用了Struts的标签的话页面就和Struts捆绑在了一起,脱离了Struts就不太好使了,相比JSTL更通用些。不清楚的地方自己再Google下。
------解决方案--------------------
<script language="javascript">
function chkAll_onclick(){
if(typeof(adform.city) == "object"){
if(adform.Allcity.checked){
SelAll();
}
else{
unSelAll();
}
}
}
function SelAll(){
var intCount;
var result="";
if(adform.all("city").length > 1)
{
for(intCount = 0; intCount < adform.all("city").length; intCount++)
{
adform.city(intCount).checked = true;
result=result+adform.city(intCount).value+";";
}
}
else{
adform.city.checked = true;
}
alert("你选中的是:"+result);
}

function unSelAll(){
var intCount;
if(adform.all("city").length > 1)
{
for(intCount = 0; intCount < adform.all("city").length; intCount++)
{
adform.city(intCount).checked = false;
}
}
else{
adform.city.checked = false;
}
}
</script>

<td width="97">
<span class="STYLE10"> <input type="checkbox"
name="Allcity" value="checkbox" onClick="chkAll_onclick()">
全国 </span>
</td>
<td width="133">
<span class="STYLE10"> <input type="checkbox"
name="city" value="北京市"> &nbsp;北京市 </span>
</td>
------解决方案--------------------
不能直接定义个String数组变量,然后用mutibox吗?