在 jQuery 中调整 HTML 表格的宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/718565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:37:48 来源:igfitidea点击:
Resizing the HTML table width in jQuery
提问by venkatachalam
I need to vary a table
's width after a click event in jQuery.
我需要table
在 jQuery 中的单击事件之后改变 a的宽度。
HTML:
HTML:
<table class="zebra" border=0>
Case 1:
情况1:
$("table.zebra").css("width","600px");
Case 2:
案例2:
$("table.zebra").css("width","200px");
CSS:
CSS:
table.zebra{}
table.zebra tr.even td, table.zebra tr.even th { background-color:#FDD017; }
table.zebra tr.odd td { background-color:#FFF380; }
This does not change the table
's width like I want.
这不会table
像我想要的那样改变的宽度。
What am I doing wrong?
我究竟做错了什么?
回答by William Brendel
This should do the trick.
这应该可以解决问题。
<table class="zebra">
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</table>
<script type="text/javascript">
$(function() {
$('table.zebra').attr('width', 500);
});
</script>
回答by Konstantin Tarkus
回答by Paul Hachmang
This should do the trick
这应该可以解决问题
$("table.zebra").width('200px');