2016-12-11 36 views
0

我想根據切換是否處於活動狀態(選中)或灰色出格。該JS似乎被觸發,當我選擇切換雖然DIV沒有被淡出從撥動開關灰掉div

修身模板

- @products.each do |product| 
    .mdl-cell.mdl-cell--4-col.item-border.mdl-shadow--2dp 
     .mdl-cell.mdl-cell--1-col.mdl-cell--10-offset 
     label.mdl-switch.mdl-js-switch.mdl-js-ripple-effect for=product.name 
      input.mdl-switch__input checked="checked" type="checkbox" id=product.name/
      span.mdl-switch__label 
     .mdl-cell.mdl-cell--12-col 
     h4.teal-heading= product.name 
     - @properties.each do |property| 
     .mdl-cell.mdl-cell--12-col 
      .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--12-col 
      input.mdl-textfield__input type="text" id=property.id 
      label.mdl-textfield__label for=property.id 
       = "#{property.name } Price" 

jQuery的

$('.mdl-switch__input').click(function(){ $(this).parent('.mdl-cell--4-col').$(this).fadeTo(500, 0.2); }); 
+0

感謝修復Dekel,現在更具可讀性。 –

回答

1

我相信這應該做的伎倆。

$('.mdl-switch__input').click(function() { 
    $(this).closest('.mdl-cell--4-col').fadeTo(500, 0.2); 
});