Bru*_*uno 10
让我们从选择单元格开始:
var $tds = $("td");
// better with a context
// var context = "#mytable";
// var $tds = $("td", context);
Run Code Online (Sandbox Code Playgroud)
$ .fn.filter将匹配元素的集合减少为与选择器匹配的元素或传递函数的测试.
function isHighterThan ($el, threshold) {
return $el.height() >= threshold;
}
var $bigTds = $tds.filter(function () {
return isHighterThan($(this), 200);
});
Run Code Online (Sandbox Code Playgroud)
最后将新样式应用于匹配元素.
$bigTds.each(function () {
$(this).css("width", "400px");
});
Run Code Online (Sandbox Code Playgroud)
<table>
<tr>
<td class="cell">
...
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$('.cell').each(function() {
if($(this).height()>=200)
$(this).width(...);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3855 次 |
| 最近记录: |