HTML DOM td/th abbr 屬性
定義和用法
abbr 屬性可設置或返回表元中內容的縮寫版本(針對非可視的媒介,比如語音和盲文)。
如果設置了該屬性,用戶只能聽到abbr 屬性的值(不是單元中的內容)。
語法
設置abbr 屬性:
tdObject.abbr="text"
或者
thObject.abbr="text"
或者
thObject.abbr="text"
返回abbr 屬性:
tdObject.abbr
或者
thObject.abbr
或者
thObject.abbr
提示: abbr屬性沒有默認值。
瀏覽器支持
所有主流瀏覽器都支持abbr 屬性。
實例
實例
下面的例子可提示第一個單元格的abbr::
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var table=document.getElementById("myTable");
alert(table.rows[0].cells[0].abbr);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td abbr="def">保持名称简短的缩写,浏览器可能重复显示它们。</td>
<td>单元格数据</td>
</tr>
<tr>
<td>单元格数据</td>
<td>单元格数据</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">获取第一个单元格的缩写</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var table=document.getElementById("myTable");
alert(table.rows[0].cells[0].abbr);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td abbr="def">保持名称简短的缩写,浏览器可能重复显示它们。</td>
<td>单元格数据</td>
</tr>
<tr>
<td>单元格数据</td>
<td>单元格数据</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">获取第一个单元格的缩写</button>
</body>
</html>
嘗試一下»
td/th對象