JSP代码:
<s:iterator value="accessProfileList" id="apfResult" status="apfStat">
<tr class="country_tr">
   <td class="grant" id="grant${apfStat.index}">
<web:checkBox checkedValue="1" value="${menuCountryList[apfStat.index].grantFlag}" property="menuCountryList[${apfStat.index}].grantFlag" onClick="enableBaseOnDefCBOrNot(this);"/>
   </td>
  <td id="country${apfStat.index}">
      <s:property value="#apfResult.description" />
      <s:hidden name="menuCountryList[%{#apfStat.index}].id" />
      <s:hidden name="menuCountryList[%{#apfStat.index}].accessProfileCode" value="%{#apfResult.code}"/>
  </td>
  <s:if test="!localeList.isEmpty()">
   <s:iterator value="localeList" id="result" status="stat">
  <td class="countryLabel">
    <s:textfield name="menuCountryList[%{#apfStat.index}].label%{#stat.index + 1}" size="20" maxlength="100" disabled="true"/>
   </td>
  </s:iterator>
  </s:if>
<td id="labelType${apfStat.index}">
   <web:checkBox checkedValue="G" value="${menuCountryList[apfStat.index].labelType}" property="menuCountryList[${apfStat.index}].labelType" disabled="true" onClick="enableLabelInputOrNot(this);"/>
</td>
</tr>
</s:iterator>JQuery代码:
each(
function(i) {
var grantFlag = "menuCountryList[" + i + "].grantFlag";
var countryLable = "menuCountryList["+i+"].label";
var lableType = "menuCountryList["+i+"].labelType";
if ($(":checkbox[name='"+grantFlag+"']").attr("checked") == true) 
{
$("input[type='text'][name^='"+countryLable+"']").attr("disabled","");
$(":checkbox[name='"+lableType+"']").attr("disabled","");
         if($(":checkbox[name='"+lableType+"']").attr("checked") == true)
{
$("input[type='text'][name^='"+countryLable+"']").val("");
$("input[type='text'][name^='"+countryLable+"']").attr("disabled", true);
$(":checkbox[name='"+lableType+"']").attr("disabled","");
}
}
else 
{
$(":checkbox[name='"+grantFlag+"']").attr("checked","");
$("input[type='text'][name^='"+countryLable+"']").attr("disabled", true);
}
});
虽然我相信大家都会看懂这段代码,但我还是简单说下这段代码的意思:
从一个list中取得数据,循环成一个table,table每一行的第一列和最后一列是一个checkbox。现在我需要使用JQuery来进行判断,如果该行的第一列,也就是第一个checkbox被勾选,则该行的所有数据才可以操作,否则,该行的所有数据是disable的,我原来是用循环来进行判断,有没有可以不使用循环来进行判断呢?

解决方案 »

  1.   

    对jQuery不是很熟,刚刚学习,记得jQuery有一个each方法,应该可以解决
      

  2.   

    可以的,根据 tr class="country_tr" 写一个方法,如果每一个td中的checkbox checked=true
    则不可修改
      

  3.   

    使用循环挺好的啊
    即使用each,也只是你的代码中没看到循环,Jquery仍然执行了循环,没提高效率
      

  4.   

    http://blog.csdn.net/xiaomaha/archive/2011/06/24/6566177.aspx