2013-10-04 20 views
1

我有一個項目列表,我需要做的是能夠檢查該列表項中的複選框,然後選中複選框該列表項變爲啓用狀態。這是我迄今爲止所做的一個JSFiddle。這將在頁面上啓用具有該類名稱的所有複選框。因爲這是一個JS文件,所以這些列表項是在一個kendo模板中生成的,所以我需要帶有類名的文本框。當在列表項中選中複選框時,只啓用該列表項中的文本框 - 按類Jquery

謝謝

<ul id="productsFoundList" data-role="listview" data-style="inset" class="km-list" data-bind="source:foundProducts" data-template="productsFound-listview-filtering-template"> 
<li> 
    <label>code - desc 
     <input type="checkbox" name="eventActionToBeTaken" class="productsUl" /> 
     <div style="position: relative; padding-top:18px; padding-bottom:15px"> 
      <div style="margin-left:80px"> 
       <label style="color:grey">Qty</label> 
       <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/> 
       <label style="color:grey">Price</label> 
       <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/> 
       <label style="color:grey">Discount(%)</label> 
       <input type="number" value="" class="productsFoundInputBorders" disabled/> 
      </div> 
      <div style="padding-top:5px; "> 
       <label style="color:grey; margin-left:64px">Notes</label> 
       <input class="productsFoundInputBorders" type="text" style="width:530px !important;" value="" disabled/> 
      </div> 
     </div> 
    </label> 
</li> 
<li> 
    <label>code - desc 
     <input type="checkbox" name="eventActionToBeTaken" class="productsUl" /> 
     <div style="position: relative; padding-top:18px; padding-bottom:15px"> 
      <div style="margin-left:80px"> 
       <label style="color:grey">Qty</label> 
       <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/> 
       <label style="color:grey">Price</label> 
       <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/> 
       <label style="color:grey">Discount(%)</label> 
       <input type="number" value="" class="productsFoundInputBorders" disabled/> 
      </div> 
      <div style="padding-top:5px; "> 
       <label style="color:grey; margin-left:64px">Notes</label> 
       <input class="productsFoundInputBorders" type="text" style="width:530px !important;" value="" disabled/> 
      </div> 
     </div> 
    </label> 
</li> 

  $("#productsFoundList").click(function() { //when list click 
     $(".productsUl").each(function() { //for each checkbox 
      if($(this).is(":checked") == true) 
      { 
       $("#basketButton").show(500); 
      } 
     }); 

     if($('.productsUl:checked').length == 0) 
     { 
      $("#basketButton").hide(500); 
     } 
    }); 

    $("#productsFoundList").click(function() { 
     if ($(".productsUl").is(":checked") == true) { 
      $(".productsFoundInputBorders").prop('disabled', false); 
     } 
     else 
     { 
      $(".productsFoundInputBorders").prop('disabled', true); 
     } 
    }); 
+0

你的小提琴無關 – Rex

+0

對不起,更新@Rex – user2681625

回答

0

嘗試

var $basket = $("#basketButton"); 
var $checks = $(".productsUl").change(function() { //for each checkbox 
    $(this).next().find(".productsFoundInputBorders").prop('disabled', !this.checked); 
    $basket.stop(true, true)[$checks.filter(':checked').length == 0 ? 'hide' : 'show'](500) 
}); 

演示:Fiddle

+0

謝謝!我不得不添加$(「#productsFoundList」)。點擊(函數(){之前你的代碼,但它的工作,然後! – user2681625

+0

我沒有注意到,雖然關閉#basket按鈕不像以前那樣隱藏,我需要的外觀隱藏,我怎麼可以這樣做? – user2681625

+0

按鈕功能再次工作,但現在不復選框一,謝謝你的方式 – user2681625

相關問題