2017-04-04 18 views
0

無効行が1つ存在する場合、すべての行を有効にするにはどうすればよいですか。私はテーブルの中に2種類のボタンがあります。最初のボタンをクリックすると、無効になっているすべてのボタンが有効になります。 2番目のボタンをクリックすると、それが割り当てられている特定の行が有効/無効になります。1つの無効行が存在する場合にすべての行を有効にする方法jQuery

HTML

<tr class="${fn:substring(monthInfo.month, 0, 3)}"> 
    <c:if test="${stat.first}"> 
    <td class="monthName" rowspan="6" value="${fn:substring(monthInfo.month, 0, 3)}"> 
     <div class="vertical-text"> 
     ${fn:substring(monthInfo.month, 0, 3)}<br> 
     <img src="resources/images/edit.png" width="20%" href="#" /> 
     </div> 
    </td> 
    </c:if> 
    <td><img class="editButt" src="resources/images/edit.png" href="#" /></td> 
    <td>${weekInfo.weekStart}</td> 
    <td>${weekInfo.weekEnd}</td> 
    <c:forEach items="${weekInfo.weeklyData}" var="week"> 
    <td><input type="text" name="cell" class="hours" maxlength="2" value="${week}"></td> 
    </c:forEach> 
    <td class="weekTotal ibm-bgcolor-green-10 ">${weekInfo.totalHrs}</td> 
    <td class="holidayTotal">${weekInfo.totalHo}</td> 
    <td class="vacationTotal">${weekInfo.totalVl}</td> 
    <td class="sickTotal">${weekInfo.totalSl}</td> 
    <td><input type="text" name="cell" class="remarks" value="${weekInfo.remarks}"></td> 
</tr> 

jQueryの

$('.editButt').click(function() { 
    $(this).closest('tr').find('input:text').prop('disabled', function(i, v) { 
    return !v; 
    }); 
}); 

$('.monthName').click(function() { 
    $("#test1table tbody tr").each(function() { 
    var className = $(this).closest('tr').find('td:first').text().trim(); 
    var value = $('.' + className).find('input:text').is(':disabled'); 
    if (!value) { 
     disableRows(); 
    } else { 
     $('.' + className).find('input:text').prop('disabled', function(i, v) { 
     return !v; 
     }); 
    } 
    }); 
}); 

ここに何が起こるかの2行が有効になっていることです。ボタンをクリックすると、最初のボタン(.monthName)が表示されます。有効になっている2つの行が無効になり、無効な行が有効になります。

しかし、私は最初のボタンをクリックしたいです。属性に関係なく、すべての行が有効になります。

+0

結果HTMLを共有できますか?そのcoldfusionの構文ですか? –

答えて

0

しかし、私は最初のボタンをクリックしたいと思います。属性に関係なく、すべての行が有効になります。

すべてのボタン

$("#enable-all").click(function(e) { 
    $("table").removeClass("disabled"); 
    $("tbody tr").removeClass("danger"); 
    $("table input, table button").prop("disabled", false); 
}); 

を無効にし、すべてのボタン

$("#disable-all").click(function(e) { 
    $("table").addClass("disabled"); 
    $("tbody tr").addClass("danger"); 
    $("table input, table button").prop("disabled", true); 
}); 

またはトグルボタンを有効にし

$("#toggle").click(function(e) { 

    $("table").toggleClass("disabled"); 
    $("tbody tr").toggleClass("danger"); 
    var isDisabled = $("table").hasClass("disabled"); 

    if (isDisabled) { 
    $("table input, table button").prop("disabled", true); 
    } else { 
    $("table input, table button").prop("disabled", false); 
    } 

}); 

jsfiddle

関連する問題