時放在桌子外面工作,我可以得到checkbox
,但我怎樣才能得到它的工作toggle/inside
行與fontawesome-trash
即可。?通過一行strike line or red color
來指示刪除/未刪除。刪除複選框不更新該行的顏色
這裏是snippet
時放在桌子外面工作,我可以得到checkbox
,但我怎樣才能得到它的工作toggle/inside
行與fontawesome-trash
即可。?通過一行strike line or red color
來指示刪除/未刪除。刪除複選框不更新該行的顏色
這裏是snippet
嘗試這個請運行該代碼段
您需要使用.closest()
.closest(): -對於組中的每一個元素,得到第一個元素通過測試元素本身並遍歷DOM樹中的祖先來匹配選擇器。從當前元素開始。向上行進,DOM樹,直到找到一個匹配的供選擇
$('.clsChk').click(function(){
if($(this).prop('checked')){
\t \t \t $(this).closest('tr.rowClass').css({'color':'red'});
}
else{
\t \t $(this).closest('tr.rowClass').css({'color':'black'});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<label for="checkboxID"> Del/Undelete </label>
<input type="checkbox" id="checkboxID" />
<table id="tableID">
<tbody>
<tr class="rowClass">
<td>** 1) First child cell of '.rowClass'</td>
<td>** 2) Second child cell of '.rowClass' </td>
<td>** 3) this checkbox needs a delete
<input class='clsChk' type="checkbox" id="checkboxID" />
</td> <!--how to make this work-->
</tr>
<tr class="rowClass">
<td>No class for this row</td>
<td>(Still no class)</td>
</tr>
<tr class="rowClass">
<td>** 1) First child cell of '.rowClass'</td>
<td>** 2) Second child cell of '.rowClass' </td>
<td>** 3) this checkbox needs a delete
<input class='clsChk' type="checkbox" id="checkboxID" />
</td> <!--how to make this work-->
</tr>
<tr class="rowClass">
<td>** 1) First child cell of '.rowClass'</td>
<td>** 2) Second child cell of '.rowClass' </td>
<td>** 3) this checkbox needs a delete
<input class='clsChk' type="checkbox" id="checkboxID" />
</td> <!--how to make this work-->
</tr>
</tbody>
</table>
使用parents
和is(":checked")
託運與否。
$('input:checkbox').change(function(){
if($(this).is(":checked")) {
$(this).parents('tr').addClass("red");
} else {
$(this).parents('tr').removeClass("red");
}
});
.red {
color : red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tableID">
<tbody>
<tr class="rowClass">
<td>** 1) First child cell of '.rowClass'</td>
<td>** 2) Second child cell of '.rowClass' </td>
<td>** 3) this checkbox needs a delete <input type="checkbox" id="checkboxID" /></td> <!--how to make this work-->
</tr>
<tr>
<td>No class for this row</td>
<td>(Still no class)</td>
</tr>
</tbody>
</table>
嗨,在m html片段中...我在裏面有另一個輸入文本框,用'class = textBox' ---我*更新的* html代碼片段爲'
有沒有其他的js你在你的博客上做的東西 – transformer
@transformer - 見上面的代碼和示例代碼 – prog1011
你好,這是偉大的,我想知道,如果有喜歡的dropdownlists等其他控制......將這些控件也。也改變顏色。我只想改變文本的顏色,並在開關/取消刪除 - 將其恢復到以前的狀態 – transformer
@transformer這隻會改變文本顏色。它不會更改任何HTML控件的顏色。 如果這個答案可以幫助你,然後請投票並打勾作爲答案......所以它會幫助其他人找出正確的答案。 – prog1011