我创建了一个小的JS,它可以在悬停时更改值,稍后会更改它的样子。我的表格由每个标题下有3列构建而成。我想要实现的是,如果您将某个列悬停,则会将文本更改为示例5000
,但如果需要,它将保留所有列大小相同,并且必须通过旁边的其他列。目前通过阅读我的代码,我将它设置为在中间列中添加5000
,因此它下面的列将因此而调整大小。更改悬停的表格文本
为了说清楚我想实现的目标是:将中间栏文本更改为5000
,并且不因此而调整其他栏的大小。
$(document).ready(function() {
$('.wep-data-P1').on({
mouseenter: function() {
$('.wep-data-P1').html('5000');
$('.wep-data-P1').first().html('');
$('.wep-data-P1').last().html('');
$('.wep-data-P1').css('border-right', 'none');
$('.wep-data-P1').css('border-left', 'none');
},
mouseleave: function() {
$('.wep-data-P1').html('5000');
$('.wep-data-P1').first().html('0');
$('.wep-data-P1').last().html('0');
$('.wep-data-P1').css('border-right', '2px solid #ccc');
$('.wep-data-P1').css('border-left', '2px solid #ccc');
}
});
\t });
.wep-name{
width: 295px;
}
.wep-data{
width: 40px;
text-align: center;
padding: 5px;
}
.wep-cond{
text-align: center;
}
table, th, td {
margin: 5px;
font-size: 18px;
}
th{
border-bottom: 2px solid #ccc;
border-right: 2px solid #ccc;
}
td{
border-bottom: 2px solid #ccc;
border-right: 2px solid #ccc;
border-left: 2px solid #ccc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<th>Name</th>
<th colspan="3" class="wep-cond">P1</th>
<th colspan="3" class="wep-cond">P2</th>
<th colspan="3" class="wep-cond">P3</th>
<th colspan="3" class="wep-cond">P4</th>
<th colspan="3" class="wep-cond">P5</th>
</tr>
<tr>
<td class="wep-name">Apple</td>
<td class="wep-data wep-data-P1">0</td>
<td class="wep-data wep-data-P1">0</td>
<td class="wep-data wep-data-P1">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
<tr>
<td class="wep-name">Banana</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
<tr>
<td class="wep-name">Pineapple</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
</table>
它的发生,因为你要删除这是2px的边框,因此被去除去除X 2px的边框数,并且表进行调整。 – inarilo
@inarilo发生这种情况的原因可能更多。文字太大,将其他大小调整为相同大小 –
你是对的,第一次是因为文本,之后,这是因为边界 – inarilo