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

一个简单的程序
<html>
<body>

<script type="text/javascript">
function sum(){
    var a=5,b=6;
}
sum();
if(a<b)
{
    alert("hehe");
}
else
{
    alert("haha");
}
</script>

</body>
</html>
为什么弹不出来“hehe”,哪里错了吗?
javascript function html

------解决方案--------------------

function sum(){
    var a=5,b=6;
    if(a<b)
    {
        alert("hehe");
    }
    else
    {
        alert("haha");
    }
}
sum();


a,b定义在方法里面,外面访问不到的。