2007-08-06

关于typeof运算符

关键字: javascript

typeof 运算符返回一个用来表示表达式的数据类型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。

一个很简单的例子

<html>
<head>
<script language="JavaScript">
 var a=function(){
  alert("This is in the function of a");
 }
        document.writeln("返回string,typeof('aa')=="+typeof('aa'));
 document.writeln("<br/>返回number,typeof(8)=="+typeof(8));
 document.writeln("<br/>返回boolean,typeof(true)=="+typeof(true));
 document.writeln("<br/>返回object,typeof(document.getElementById('div'))=="+typeof(document.getElementById('div')));
 document.writeln("<br/>返回undefined,typeof(cc)=="+typeof(cc));
 document.writeln("<br/>返回function,typeof(a)=="+typeof(a));
        
</script>
</head>
<body>
<div id="div"></div>
</body>
</html>

评论
发表评论

您还没有登录,请登录后发表评论

weiweichen1985
搜索本博客
我的相册
E6c390da-d0cb-3350-97d4-83ec6586912c-thumb
2008-6-26
共 122 张
存档
最新评论