<div class="codetitle"> <span><a style="CURSOR: pointer" data="77515" class="copybut" id="copybut77515" onclick="doCopy('code77515')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code77515"> <br> <br><title>JS反射</title> <br><script type="text/javascript"> <BR>/* <BR>* 反射 <BR>*/ <BR>function forwindow() { <BR>for (var i in window) { /*循环 <BR>if (window[i] === "wsenmin") { /* 三个等号,先比较类型 <BR>return i; /* 类型如果不同的话不予比较,自动跳过 <BR>} /* 类型相同才会比较值 <BR>} <BR>} <BR>var name = "wsenmin"; <BR>var trimName = forwindow(); <BR>alert(trimName); <BR></script> <br> <br> <br> <br> <br> </div> <br>/* 两个等号直接比较值,但是类型不能相互转换的时候报错 <br>window[i] === "wsenmin1" <br>window[i] == "wsenmin1" <br>大家相互比较一下