我试图合并两个条件 在一个“如果”声明,如果可能的话。
我想首先检查屏幕宽度, 然后看看表格的行或第一行中是否有超过2 tds。 如果有某种函数的话 。
这是我在宽度方面的第一个部分,但我在需要满足的其他条件中又应如何补充呢?
var width = parseInt($(window).width());
if (width<=610) {
//Need to add the other condition that is a table has more than 2 td s in a row
}
这是我想运行的真实代码。 请看我的评论, 如果执行超过两列的话 。
var width = parseInt($(window).width());
if (width<=610) {
//Need to figure out how execute this if there are more than 2 columns in the table???
$( .content table ).replaceWith(function() {
var $th = $(this).find( th ); // get headers
var th = $th.map(function() {
return $(this).text();
}).get(); // and their values
$th.closest( tr ).remove(); // then remove them
var $d = $( <div> , { class : responsive-table });
$( tr , this).each(function(i, el) {
var $div = $( <div> , { class : box grey-bg }).appendTo($d);
$( td , this).each(function(j, el) {
var n = j + 1;
var $row = $( <div> , {
// class : row- + n
class : row
});
$row.append(
$( <span> , {
// class : label- + n,
class : label ,
text: th[j]
}), : , $( <span> , {
// class : data- + n,
class : data ,
text: $(this).text()
})).appendTo($div);
});
});
return $d;
});
};