typeof()运算符:

来源:互联网 发布:ubuntu 14.04 镜像源 编辑:程序博客网 时间:2024/05/22 03:19

typeof()运算符:
经常会在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组.
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"

原创粉丝点击