小码哥的IT人生

HTML DOM vAlign 属性

JavaScript基础 2022-06-08 17:20:38小码哥的IT人生shichen

HTML DOM vAlign 属性

定义和用法

vAlign 属性设置或返回数据在行中的垂直对齐方式。

语法

tablerowObject.vAlign=top|bottom|middle|baseline

实例

下面的例子更改了数据在行中的垂直排列方式:

<html>
<head>
<script type="text/javascript">
function topAlign()
  {
  document.getElementById('tr2').vAlign="top";
  }
</script>
</head>
<body>
<table width="50%" border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
<th>Text</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
<td>Hello my name is Peter Griffin.
I need a long text for this example.
I need a long text for this example.</td>
</tr>
</table>
<br />
<input type="button" onclick="topAlign()"
value="Top-align table row" />
</body>
</html>

TIY

完整实例【垂直对齐行中的单元格内容】:

<html>
<head>
<script type="text/javascript">
function topAlign()
  {
  document.getElementById('tr2').vAlign="top";
  }
</script>
</head>
<body>
<table width="50%" border="1">
<tr id="tr1">
<th>名</th>
<th>姓</th>
<th>文本</th>
</tr>
<tr id="tr2">
<td>John</td>
<td>Adams</td>
<td>你们好。我是名字是 John Adams。
在本例中,我需要一段长的文本。
在本例中,我需要一段长的文本。
在本例中,我需要一段长的文本。</td>
</tr>
</table>
<br />
<input type="button" onclick="topAlign()" value="上对齐表格行" />
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024