使用jQuery选择具有rowspan的单元格

时间:2015-01-29 05:56:17

标签: jquery html

我有自动生成html表,这个表的一些单元格有rowspan属性。如何选择这个细胞?

3 个答案:

答案 0 :(得分:0)

$( "[rowspan]" )

将为您提供所有带有rowspan属性的标记

答案 1 :(得分:0)

JSFiddle

$(document).ready(function() {
    $('table').find('td[rowspan]').css('background-color', 'red');

    // or
    // $('table').find('td[rowspan=2]').css('background-color', 'red');
});

答案 2 :(得分:0)

可能会有效:

$(document).ready(function() {
  $('table td[rowspan="*"]').css('background-color', 'red');
});

或者这个:

$(document).ready(function() {
  $("table td").each(function () {
    if ($(this).attr("rowspan"))
      $(this).css('background-color', 'red')
  });
});