js的枚举型变量
来源:忘了
搜集整理:sagahu@163.com
<pre>
js的枚举型变量
用于全局变量等。
注意JS大小写敏感。
</pre>
<script language="javascript">
var curChannel = '210';
var channels={
a : '220',
b : '221',
c : '222'
};
// 调用枚举
alert(channels.b);
// 判断枚举中是否包含某元素值
if (curChannel in channels) {
alert("含有这个属性值");
} else {
alert("不含有这个属性值");
}
// 判断枚举中是否包含某元素名
if ('a' in channels) { // 检查属性名
alert("检查属性-true");
} else {
alert("检查属性-false");
}
// 遍历枚举
var nem={A:1,B:2,C:3}
for(i in nem)
alert(nem[i]);
</script>