首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript新手有关问题

2012-08-24 
javascript新手问题以下代码为什么不弹出alert框?我是想用一个alert来弹出p中的文本。htmlheadscrip

javascript新手问题
以下代码为什么不弹出alert框?
我是想用一个alert来弹出<p>中的文本。


<html>
<head>

<script type="text/javascript">
var e = document.getElementById("pp");
var str=e.firstChild.nodeValue
alert(str);

</script>

</head>

<body>

<p id="pp" title="pTitle" >ABCDEFG</p>

</body>

</html>

[解决办法]

HTML code
<html><head><script type="text/javascript">window.onload=function(){    var e = document.getElementById("pp");    var str=e.firstChild.nodeValue    alert(str);}</script></head><body><p id="pp" title="pTitle" >ABCDEFG</p></body></html> 

热点排行