我正在使用 Javascript 和 jQuery 创建一个表,我希望它在您单击表第一行上的 td 时,然后该列中的其余 td 下拉。让我尝试通过显示我的代码来解释它。这是我的Javascript:
$(document).ready( function() {
createTr(heights);
});
function createTr (heights) {
for (var h=0; h<heights.length; h++) { // h is row number, i is column number!
var theTr = $("<tr>", { id: "rowNumber" + h});
for (var i=0; i<heights.length-3; i++) { // IF EXTRA TD'S ARE SHOWING< CHANGE 3 TO SOMETHING ELSE
theTr.append($("<td>", { "class": "row"+h + " column"+i,
html: heights[h][i]
}));
}
$('#newTable').append(theTr); // append <tr id='rowNumber0'> to the table, which is in the html
if (h != 0) {
$('.row' + h).addClass('invisible'); // hide all the rows except the first row
}
$('.column0').removeClass('invisible'); // show the first column
$('.row0').not('.column0').on({
mouseenter: function() {
$(this).addClass('column0Hover');
},
mouseleave: function() {
$(this).removeClass('column0Hover');
}
});
} // end for
} // end function
这基本上创建了 td,每个 td 都类似于这种格式
<td class="rowh columni">
参数'heights'只是一个数组,例如,它可以是
var heights = [['headerOne', 'headerTwo'], ['someTd', 'anotherTd'],];
它会使用这些词创建一个表, headerOne 和 headerTwo 将在第一行, someTd 和 anotherTd 将在第二行。
我想要它,以便 .row0 .column0 中的 td 默认具有红色背景色。这很奇怪,因为$('.row0').not('.column0').on({
不选择 td 和.row0
.column0
, 并.row0
选择它 . column0
选择它,所以它的类 For Sure is.row0
.column0
但是,当我去 CSS 并做
.row0 .cloumn0 {
background-color: #063 !important;
}
它不起作用。当我尝试像这样选择它作为查询选择器时
$('.row0 .column0')
它仍然没有选择任何东西。怎么来的?