我正在動態創建一個表,並將一些預先格式化的文本從xml文件包含到它中,但我的表延伸以適合整個內容,而不是我想要固定表格大小,橫向滾動也可以,請提供一些解決方案。如何修復td或表的寬度,使其不會延伸
這裏是我的代碼
$('#detailTable').empty();
$('<div width="100%">')
.attr('id','dblistSpan')
.html('<div class="titleBlue">Configuration>System>DBList</div>'+
'<table id="grid" style="border:#2F5882 1px solid;width:100%;overflow:hidden;" cellspacing="1" cellpadding="1">'+
'<tr style="color :#FFFFFF;background-color: #8EA4BB">'+
'<th><b>DBlist'+
'</b></th>'+
'<tr>'+
'<tr style="color :#2F5882;background-color: #EDF1F5;width:100%;overflow:hidden;">'+
'<td style="width:100%;overflow:hidden;"><pre>'+dblist+
'</pre></td>'+
'<tr>'+
'</table>'+
'</div>')
.appendTo('#detailTable');
只需提供固定的寬度例如'width:500px;溢出:滾動;' –
@Shadow Wizard:如果分辨率增加,它會保持嗎? – abi1964
不,這是固定寬度的缺點......但您可以在這種情況下使用JavaScript並根據屏幕分辨率應用一次固定寬度。代碼非常簡單,讓我知道你是否想要。 –