0

我有一个表格,其中每一行都包含文档名称,并且每一行的开头都有一个复选框。某些复选框被禁用。我想添加text-decoration:line-through到该行,以便用户可以轻松识别该行,因为复选框已禁用,因此无法选择该行。如何使用 JavaScript 或 jQuery 做到这一点?

在下面的示例中,文档名称为 2 的行应该是直通的。

<tr>
    <td>
    <input type="checkbox" name="doclist" id="someId" value="someId"  onchange="updateList('someId')">Doc name 1
    </td>
</tr>

<tr>
    <td>
    <input type="checkbox" name="doclist" id="AnotherId" value="AnotherId"  onchange="updateList('AnotherId')" disabled>Doc name 2
    </td>
</tr>

我尝试了以下。

$('input[type="checkbox"]').filter(function() {
var disabledRow = this.disabled;
disabledRow.addClass("lineThrough");
});

CSS

.lineThrough{
text-decoration:line-through;
}
4

2 回答 2

1

演示

$('table tr td input[type="checkbox"]').each(function(){
    if($(this).prop('disabled')){
       $(this).parents('tr').css('text-decoration','line-through');
    }
});

如果你想和班级一起工作

$('table tr td input[type="checkbox"]').each(function () {
    if ($(this).prop('disabled')) {
        $(this).parents('tr').addClass('lineThrough');
    }
});

正如UwebB所建议的那样

.closest('tr').parents('tr')

$('table tr td input[type="checkbox"]').each(function () {
    if ($(this).prop('disabled')) {
        $(this).closest('tr').addClass('lineThrough');
    }
});
于 2013-08-05T07:20:53.300 回答
0
$('input[type="checkbox"]:disabled').parent().addClass('lineThrough');
于 2013-08-05T07:26:24.293 回答