1

我允许用户使用 <input type=file> 按钮将文件添加到页面。每个文件都作为新行添加到表中。我需要为奇数行和偶数行设置不同的背景颜色。我现在在我的风格中使用第 n 个孩子,但我需要 IE8 的解决方案。

在 IE 8 中:每次用户添加新文件时,我都需要表格来设置行的背景颜色。

到目前为止,这是我的代码:

<style>
 .OddRow {
    background: #eeeeee;   
    border-bottom: 1px solid #ccc;  
}

.EvenRow {
    background: #fff;     
    border-bottom: 1px solid #ccc;
}

</style>

        <span class="addfiles">
            <span>Add Files...</span>
            <input id="addFile" type="file" name="files[]" multiple>
        </span>

<table class="table table-striped">
    <tbody class="files"></tbody>
</table>

 <script>
    $(function () {
        $('#addFile').change(function () {
            $(".table table-striped tbody tr:even td").addClass('EvenRow');
            $(".table table-striped tbody tr:odd td").addClass('OddRow');
        });     
    });

 </script>

正在调用更改函数,但未应用行样式。我已经为 .addClass 代码尝试了许多事件和位置,所以我真的很感激对此的另一种看法。

谢谢。

4

1 回答 1

1

您正在选择td而不是表格行本身。也table-striped没有正确定位(假设它是另一个类)。将您的 jQuery 选择器更改为

   $(".table.table-striped tbody tr:even").addClass('EvenRow');
    $(".table.table-striped tbody tr:odd").addClass('OddRow');
于 2013-02-20T20:49:13.513 回答