JavaScript 判断性别、类型
匿名用户1572015-09-17 10:49
在开发中我们经常用1代表男生、0代表女生。
在jsp中常用的是使用三目运算符,但是html静态页面怎么开发?
jsp中判断:
${sex==1?'男':sex==0?'女':'妖'}
html页面中判断:
<html>
<head>
<title>studyjava测试</title>
<script>
var sex = {
1 : "<span style='color:green'>男</span>",
0 : "<span style='color:red'>女</span>"
};
</script>
</head>
<body>
<script>document.write(sex['0'])</script>
</body>
</html>
缺憾:如果取得值不存在会出现undefined。
