首页 > 选择结构结果错误

选择结构结果错误

<html>
<head>


<script>
function s() { 
    var person = document.forms['person'];
    if(person.sex.value=="男") { 
        alert("先生您好"); 
    } else { 
        alert("女士您好"); 
    } 
}
</script>


</head>

<body>


<form name="person">
<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女<br>
<input type="button" value="确定" onClick="s()">
</form>


</body>
</html>


先生你好,一般情况下不推荐用浏览器直接打开Html文件进行代码测试。
你的代码是没有问题的,你检查一下你的浏览器是否禁止加载本地js代码了。
不推荐用IE来开发前端代码,推荐Chrome / FireFox .
如果是php环境可以搭建XAMPP这样的集成环境
其他架设Apache自己稍微研究一下。


兄弟你很耿直啊,我试了你的代码,没错啊???


你拿我代码试试:
1. 添加了meta标签
2. 多了一个选择,你得确定是不是你第一个判断一致不成立的问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
    function s() { 
        var person = document.forms['person'];
        if(person.sex.value=="男") { 
            alert("先生您好"); 
        } else if(person.sex.value=="女"){
            alert("女士您好"); 
        }else { 
            alert("您好"); 
        } 
    }
    </script>
</head>
<body>
    <form name="person">
    <input type="radio" name="sex" value="男">男
    <input type="radio" name="sex" value="女">女<br>
    <input type="button" value="确定" onClick="s()">
    </form>
</body>
</html>

http://jsfiddle.net/RayLiao/kbnpfu9d

没什么问题。


额,jsfiddle的预览怎么显示不了了。

【热门文章】
【热门文章】