案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<h3>演示如何访问 LEGEND 元素</h3>
6
7
<fieldset>
8
  <legend id="myLegend">Personalia:</legend>
9
  Name: <input type="text">
10
</fieldset>
11
12
<p>点击按钮来获得 legend 元素的文本。</p>
13
14
<p id="demo"></p>
15
16
<button onclick="myFunction()">试一下</button>
17
18
<script>
19
function myFunction()
20
{
21
var x = document.getElementById("myLegend").textContent;
22
document.getElementById("demo").innerHTML = x;
23
}
24
</script>
25
26
<p><b>注释:</b>Internet Explorer 8 以及更早的版本不支持 textContent 属性。</p>
27
28
</body>
29
</html>
30