<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript</title> <script type="text/javascript"> window.onload = function(){ var domObj = document.getElementById("dom"); domObj.style.color = "red"; } </script> </head> <body> <h1 id="dom">JavaScript</h1> </body> </html>
页面上所有的dom节点,窗体加载完成以后执行function方法。
参考别人的视频教程写的。