javascript - 我可以强制尝试不崩溃吗?

标签 javascript html css html-table tablelayout

假设我有这样的代码:


<table>
    <tr style="background-color: red"><td><pre>This is line one</pre></td></tr>
    <tr style="background-color: red"><td><pre></pre></td></tr>
    <tr style="background-color: red"><td><pre>This is line three</pre></td></tr>
    <tr style="background-color: red"><td><pre>This is line four</pre></td></tr>
</table>

我希望第二行与其他行的高度相同。有办法做到这一点吗?

最佳答案

为其设置样式。

tr{
   height: 20px;
}

如果你想使用 javascript (jQuery) 那么像这样。

var maxHeight =0;
$("tr").each(function(){
    if($(this).height()>maxHeight){
       maxHeight = $(this).height();
    } 
});

$("tr").css({height: maxHeight+'px'});

这是一个 jsFiddle:http://jsfiddle.net/Xtyqr/

关于javascript - 我可以强制尝试不崩溃吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4839723/

相关文章:

javascript - 将 Google Charts API 与 PHP 来源的值一起使用

javascript - 将额外数据附加到表单请求

javascript - 为什么我要在脚本标签上放置一个 ID?

javascript - jquery 褪色问题

javascript - jQuery focus() 不聚焦

javascript - Mootools DatePicker 独立版

javascript - 如何跟踪indexedDB中的ADD错误?

jquery - 你如何在对话框中打开一个 URL JQUERY UI

javascript - Angular 6 - 发生错误后 UI 卡住

javascript - 投资组合模态,自动向左填充 17px