javascript 浏览器判断 绑定事件 arguments 转换数组 数组遍历_javascript技巧
程序员文章站
2022-04-26 23:23:09
...
复制代码 代码如下:
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]);
}
循环对象的所有属性:
循环数组的所有元素: