菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>小鸟启蒙(facesoho.com)</title> </head> <body> <div class="example">第一 Div 元素 class="example"。</div> <div class="example">第二个 Div 元素 class="example"。</div> <p>点击按钮修改第一个 Div 元素的文本信息(索引值为 0 的 class="example")。</p> <button onclick="myFunction()">点我</button> <p><strong>注意:</strong> Internet Explorer 8 及更早 IE 版本不支持 getElementsByClassName() 方法。</p> <script> function myFunction() { var x = document.getElementsByClassName("example"); x[0].innerHTML = "Hello World!"; } </script> </body> </html>
运行结果