当页面开发中遇到返回值是undefined的时候,好多人想当然的认为下面这样
if (reValue== undefined){
alert("undefined");
}
使用后,就知道这样没用。解决办法就是:使用typeof
方法:
if (typeof(reValue) == "undefined") {
alert("undefined");
}
typeof 返回的是字符串,有六种可能:
"number"、"string"、"boolean"、"object"、"function"、"undefined"
使用typeof方法后就没问题了,呵呵,祝大家开发愉快,和沫沫金一样遇到好东西给大家分享
<a href="http://s.click.taobao.com/t_8?e=7HZ6jHSTaWZHHhtTlBgacoirGSIJB8%2BG25luxWzD4oLZ&p=mm_22780906_0_0" target="_blank"></a>
本文转自 沫沫金 51CTO博客,原文链接:http://blog.51cto.com/zl0828/927170,如需转载请自行联系原作者