小码哥的IT人生

HTML DOM abbr 属性

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

HTML DOM abbr 属性

定义和用法

abbr 属性可设置或返回表元中内容的缩写版本(针对非可视的媒介,比如语音和盲文)。

语法

tabledataObject.abbr=text

实例

下面的例子可提示某个单元格的 abbr:

<html>
<head>
<script type="text/javascript">
function alertAbbr()
  {
  alert(document.getElementById('td1').abbr);
  }
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td id="td1" abbr="Some text">Peter</td>
<td id="td2">Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="alertAbbr()"
value="Alert abbr" />
</body>
</html>

TIY

完整实例【返回某个单元格的 abbr】:

<html>
<head>
<script type="text/javascript">
function alertAbbr()
  {
  alert(document.getElementById('td1').abbr);
  }
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td id="td1" abbr="Some text">Peter</td>
<td id="td2">Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="alertAbbr()" value="Alert abbr" />
</body>
</html>

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

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

苏公网安备 32030202000762号

© 2021-2024