[英]Creating new table-row with colspan changes cell sizes in IE
我正在研究一個相當復雜的問題,並試圖將我的問題簡化為一個簡短的代碼示例。
當我使用jQuery在表中創建新的<tr>
並將colspan設置為column-number-of-columns時,表單元格的寬度(未在代碼中設置)改變。 這種情況在IE9中發生,但在Chrome中不發生。 我知道我可以在代碼中明確給出像元大小,但是我無法在使用的解決方案中做到這一點。
這是代碼:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript" ></script>
<script type="text/javascript">
var expanded = false;
var $detailsRow;
$(document).ready(function(){
//toggle the details row
$(".selectable-row").click(function(){
if(expanded){
$detailsRow.remove();
expanded = false;
}else{
$detailsRow = $("<tr class=\"child-row\"><td colspan=\"4\">");
$detailsRow.find("td").text("Hellohellohellohellohellohello Hellohellohellohellohellohello Hellohellohellohellohellohello Hellohellohellohellohellohello Hellohellohellohellohellohello Hellohellohellohellohellohello Hellohellohellohellohellohello Hellohellohellohellohellohello Hellohellohellohellohellohello");
$detailsRow.insertAfter($(this));
expanded = true;
}
});
});
</script>
<div style="width:1000px">
<table border="1" style="width:100%">
<tr class="selectable-row">
<td>2012-09-03 11:33</td>
<td>This is the 2nd column</td>
<td>The 3rd column</td>
<td>The last one</td>
</tr>
</table>
</div>
請注意,這是一個細微的差別,第二個被擴展,並且日期單元格稍小。
有人可以解釋為什么會這樣嗎,如果有解決辦法? 也許以某種方式用div包裹單元格的內部。 我已經盡力了。
您是否應用了任何CSS來控制單元格的寬度?是因為在單元格上添加了CSS屬性后,它的大小停止了。
<style type="text/css">
.selectable-row td { width: 25%; }
</style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.