日期:2014-05-16  浏览次数:20380 次

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>