天天看點

freemaker頁面複選框全選與反選

             <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>

               </#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);

  });

繼續閱讀