老师,求解答,谢谢
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>函数定义的位置</title>
</head>
<body>
<script type="text/javascript">
var family={};
family.me='小明';
family.wife='小花';
family.setBaby=function(sex){
if(sex=='male'){
family.sex='男';
family.baby='牛牛';
}
else{
family.sex='女';
family.baby='妞妞';
}
}
// 老师,上面能正确运行,但是下面就运行不了,不知道是哪里出问题了;
var family={
me="小明",
wife="小花",
setBaby=function(sex){
if (sex=='male'){
this.sex='男';
this.baby="牛牛";}
else{
this.baby="妞妞";
this.sex='女';
}
}
};
family.setBaby("male");
document.write(family.sex+":"+family.baby);
</script>
</body>
</html>
正在回答 回答被采纳积分+1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>函数定义的位置</title>
</head>
<body>
<script type="text/javascript">
// var family={};
// family.me='小明';
// family.wife='小花';
// family.setBaby=function(sex){
// if(sex=='male'){
// family.sex='男';
// family.baby='牛牛';
// }
// else{
// family.sex='女';
// family.baby='妞妞';
// }
// }
var family={
me:"小明",
wife:"小花",
setBaby:function(sex){
if (sex=='male'){
this.sex:'男';
this.baby:"牛牛";}
else{
this.baby:"妞妞";
this.sex:'女';
}
},
};
family.setBaby("male");
document.write(family.sex+":"+family.baby);
</script>
</body>
</html>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星