|
巧用恒等符号实现检验变量有没有定义 |
|
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>function IsDefined</title> </head> <script> function IsDefined(obj) { if( "undefined"!==obj&& ("undefined"==obj+"") ) return false; return true; } alert(IsDefined(document.sss)); alert(IsDefined("s")); alert(IsDefined("undefined")); alert(IsDefined(document)); alert(IsDefined(111222)); alert(IsDefined(document.oncontexemenu)); </script> </html> |