赞
踩
定义:getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>getElementById</title> <script type="text/javascript"> function player1() { //根据Id获取标签对象,此处是[object HTMLButtonElement] var PaulObj = document.getElementById("Paul"); //innerHTML 表示起始标签和结束标签中的内容(这个属性可读、可写) alert(PaulObj.innerHTML); } function player2() { var CurryObj = document.getElementById("Curry"); alert(CurryObj.innerHTML); } </script> </head> <body> <button id="Paul" onclick="player1()">保罗</button> <button id="Curry" onclick="player2()">库里</button> </body> </html>
运行界面
点击 按钮"保罗" 弹出 id="Paul"的button标签中的内容
点击 按钮"库里" 弹出 id="Curry"的button标签中的内容
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。