+ -
当前位置:首页 → 问答吧 → script标签的放置位置有区别的?

script标签的放置位置有区别的?

时间:2010-05-22

来源:互联网

放在<head></head>之间输出无效.
然后我在把整个script放在body之间则生效了.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//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=bg2312" /> <title>shoping list</title> <style type="text/css"> p{ color:yellow; font-family:"Arial",sans-serif; font-size:1.2em; } body{ color:white; background-color:black; } #purchases{ border:1px solid white; background-color:#333; color:#ccc; padding:1em; list-style:none; float:left; } #purchases li{ font-weight:bold; } *{margin:0;padding:0;} </style> <script type="text/javascript"> var paras = document.getElementsByTagName("p"); for(var i=0; i < paras.length; i++){ alert(paras[i].getAttribute("title")); } </script> </head> <body> <h1>What to buy</h1> <p title="a gentle reminber">Don't forget to buy this stuff.</p> <ul id="purchases"> <li>A tin of beans</li> <li>Cheese</li> <li>Milk</li> </ul> </body> </html>
 提示:您可以先修改部分代码再运行
这是怎么回事啊?

作者: rao3324180   发布时间: 2010-05-22