|
javascript 浏览器 判断 绑定事件 arguments 转换数组 数组遍历等函数
复制代码 代码如下: var $d = document;
function $i(s){return $d.getElementById(s);} var _jsc={} _jsc.client=(function(){ var t={}; var b=navigator.userAgent.toLowerCase(); t.isOpera=(b.indexOf('opera')>-1) t.isIE=(b.indexOf('msie')>-1) t.isFF=(!t.isOpera&&!t.isIE&&b.indexOf("firefox")>-1); return t;
})() _jsc.util=(function(){ var t={} t.addEvent=function(o,e,f){ if(_jsc.client.isIE){ o.attachEvent("on"+e,f) }else{ o.addEventListener(e,f,fasle); } return true } return t; })(); //window.onload=function(){_jsc.util.addEvent(document,"click",showMsg("z","d"))} _jsc.util.addEvent(document,"click",function(){showMsg("a","b")})
function showMsg() { //alert(typeof arguments) //var dd=[arguments[0],arguments[1]] //var o = {a:'aa', b:'bb', c:'cc'}; //var o = {}; o=arguments o=Array.prototype.slice.call(arguments,0); for(var p in o) { alert(o[p]); }
循环对象的所有属性: <script> var o = {a:'aa', b:'bb', c:'cc'}; for(var p in o) { alert(eval("o." + p)); } </script>
循环数组的所有元素:
<script> var arr = ['11', '22', '33']; for(var i in arr) { alert(arr[i]); } </script>
|
|