Javascript typeof 用法

时间:2013-10-20 20:49:40 

if(document.mylist.length != "undefined" ) {} 这个用法有误.
正确的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的运算数未定义,返回的就是 "undefined".
运算数为数字 typeof(x) = "number"
字符串 typeof(x) = "string"
布尔值 typeof(x) = "boolean"
对象,数组和null typeof(x) = "object"
函数 typeof(x) = "function"
typeof 运算符返回一个用来表示表达式的数据类型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
如:
alert(typeof (123));//typeof(123)返回"number"
alert(typeof ("123"));//typeof("123")返回"string"
typeof 运算符
返回一个用来表示表达式的数据类型的字符串。
typeof[()expression[]] ;
expression 参数是需要查找类型信息的任意表达式。

说明
typeof 运算符把类型信息当作字符串返回。typeof 返回值有六种可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 语法中的圆括号是可选项。

标签:Javascript,typeof
0
投稿

猜你喜欢

  • 能否用显示/隐藏层来控制FLASH播放与停止

    2008-10-27 14:08:00
  • sqlserver中去除字符串中连续的分隔符的sql语句

    2012-06-06 20:07:39
  • 另类解读SQL Server中的DateTime数据类型

    2009-01-06 11:22:00
  • Google的设计导引

    2008-04-06 14:18:00
  • python 实现一个反向单位矩阵示例

    2023-07-27 16:05:51
  • MySQL命令终端有beep声

    2009-02-26 15:27:00
  • 不同情况下修复Access数据库的实用方法

    2008-11-28 16:18:00
  • Oracle 8i在P4上的安装

    2010-07-31 13:19:00
  • Python3 解释器的实现

    2023-08-09 17:08:53
  • 一些关于SQL2005+ASP.NET2.0的问题

    2007-09-23 13:01:00
  • 网页制作 JSP与ASP 的比较

    2005-08-10 16:00:00
  • 数据库分页大全(mssql,mysql,oracle)

    2010-10-25 20:02:00
  • ASP使用xmlhttp定时触发事件

    2008-08-19 18:09:00
  • 可以实现在同一页面里的用多按钮进行提交吗?

    2009-11-01 18:04:00
  • 初学js者对javascript面向对象的认识分析

    2011-03-16 11:04:00
  • PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数

    2023-07-11 03:55:49
  • 利用mergeAttributes设置name属性

    2009-12-12 18:48:00
  • 如何实现SQL Server的分页显示?

    2010-05-18 18:36:00
  • MySQL的root密码丢失解决方法

    2011-05-05 15:56:00
  • 解决bootstrap导航栏navbar在IE8上存在缺陷的方法

    2023-09-03 10:55:07
  • asp之家 网络编程 m.aspxhome.com