Javascript typeof 用法
更新時間:2008年12月28日 20:47:41 作者:
在js里用到數(shù)組,比如 多個名字相同的input, 若是動態(tài)生成的, 提交時就需要判斷其是否是數(shù)組.
if(document.mylist.length != "undefined" ) {} 這個用法有誤.
正確的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的運算數(shù)未定義,返回的就是 "undefined".
運算數(shù)為數(shù)字 typeof(x) = "number"
字符串 typeof(x) = "string"
布爾值 typeof(x) = "boolean"
對象,數(shù)組和null typeof(x) = "object"
函數(shù) typeof(x) = "function"
typeof 運算符返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
如:
alert(typeof (123));//typeof(123)返回"number"
alert(typeof ("123"));//typeof("123")返回"string"
typeof 運算符
返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
typeof[()expression[]] ;
expression 參數(shù)是需要查找類型信息的任意表達式。
腳本之家 www.dbjr.com.cn 更多的javascript資料可以訪問
說明
typeof 運算符把類型信息當作字符串返回。typeof 返回值有六種可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 語法中的圓括號是可選項。
正確的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的運算數(shù)未定義,返回的就是 "undefined".
運算數(shù)為數(shù)字 typeof(x) = "number"
字符串 typeof(x) = "string"
布爾值 typeof(x) = "boolean"
對象,數(shù)組和null typeof(x) = "object"
函數(shù) typeof(x) = "function"
typeof 運算符返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
如:
alert(typeof (123));//typeof(123)返回"number"
alert(typeof ("123"));//typeof("123")返回"string"
typeof 運算符
返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
typeof[()expression[]] ;
expression 參數(shù)是需要查找類型信息的任意表達式。
腳本之家 www.dbjr.com.cn 更多的javascript資料可以訪問
說明
typeof 運算符把類型信息當作字符串返回。typeof 返回值有六種可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 語法中的圓括號是可選項。
相關(guān)文章
Js生成隨機數(shù)/隨機字符串的方法小結(jié)【5種方法】
這篇文章主要介紹了Js生成隨機數(shù)/隨機字符串的方法,結(jié)合實例形式總結(jié)分析了5種Js生成隨機數(shù)/隨機字符串的操作技巧,需要的朋友可以參考下2020-05-05基于JavaScript實現(xiàn)全屏透明遮罩div層鎖屏效果
這篇文章主要介紹了基于JavaScript實現(xiàn)全屏透明遮罩div層鎖屏效果的相關(guān)資料,需要的朋友可以參考下2016-01-01javascript數(shù)組常見操作方法實例總結(jié)【連接、添加、刪除、去重、排序等】
這篇文章主要介紹了javascript數(shù)組常見操作方法,結(jié)合實例形式總結(jié)分析了javascript數(shù)組的連接、添加、刪除、去重、排序等操作,代碼注釋附帶較為詳細的說明,需要的朋友可以參考下2019-06-06javascript+canvas實現(xiàn)刮刮卡抽獎效果
這篇文章主要介紹了javascript+canvas實現(xiàn)刮刮卡抽獎效果的相關(guān)資料,需要的朋友可以參考下2015-07-07