JS判断变量是否已经定义


if
( callbackfun != "undefined" ) { callbackfun(); } //发现判断不出来,最后查了下资料要用typeof //方法: if ( typeof(callbackfun) != "undefined" ) { callbackfun(); }

 

typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined

posted on 2013-01-30 15:26  yun007  阅读(13144)  评论(1编辑  收藏  举报