当前位置: 代码迷 >> JavaScript >> 一个容易的程序
  详细解决方案

一个容易的程序

热度:202   发布时间:2013-03-06 16:20:31.0
一个简单的程序
<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定义在方法里面,外面访问不到的。
  相关解决方案