freemaker页面复选框全选与反选

来源:互联网 发布:mac拷不进移动硬盘 编辑:程序博客网 时间:2024/06/05 17:32
             <tr>
                 <td align="right" style="width:120px">
                    <input type="checkbox" class="chk_list" id="checkall" checked="checked" value="" >
                    <td>全选/取消全选</td>
                 </td>
             </tr>
              <#if partnerFieldList?exists>
                  <#list partnerFieldList as partnerField>
                    <tr>
                   <td align="right" style="width:120px"><input type="checkbox" checked="checked" id="fieldNames" name="fieldNames" value="${partnerField.name}" /></td>
                   <td style="width:150px">
            ${partnerField.description}
               </td>
               <#if fieldTypeList?exists>
               <td style="width:150px">
                <select id="fieldType" name="fieldType" class="cword chosen">
                  <#list fieldTypeList as fieldType>
                                    <option value="${fieldType.id}">${fieldType.name}</option>
                                    </#list>
            </select>
               </td>
               </#if>
                    </tr>
                   </#list>
              </#if>

js实现:
  $(function(){
   $('#partnerFieldAddForm').Validform({
    btnSubmit:"#saveBtn",
    tiptype:2,
    showAllError:true,
    beforeSubmit: function(){
    var ids = "";
       var selectedCheckboxs =$("input:checked[name='fieldNames']");
       $.each(selectedCheckboxs, function(index, value){
          ids += $(value).val() +',';
        var value =  $(value).val()+'|'+$(value).parent().next().next().children().val();
        $(this).val(value);
       })
    ids = ids.substring(0, ids.length - 1);
             if (ids.length == 0) {
                $.jBox.tip('请先选择一行数据!');
                return false;
             }
    }
   });
   
   $("#checkall").click(
     function(){
     if(this.checked){
        $("input[name='fieldNames']").attr('checked', true)
     }else{
        $("input[name='fieldNames']").attr('checked', false)
         }
     }
     );
   
   
   $('.chosen').chosen({
    "no_results_text":'未找到匹配数据!',
    "width":"120px",
    "allow_single_deselect":true
   });
   $('#cancelBtn').click(function(){
    parent.jBox.close(true);
   });
  });