Prototype学习——工具函数($H,$R,Try.these,document.getElementsByClassName)
2009-07-19 20:15
731 查看
$H就是建立Hash对象的便捷方法,关于Hash对象具体参考【Prototype 学习——Hash对象 】
$R就是简历ObjectRange对象的便捷方法,关于ObjectRange对象具体参考【Prototype 学习——ObjectRange对象 】
Try.these:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.
看一个例子(不同的浏览器有不同的创建XMLHttpRequest的方法):
document.getElementsByClassName():
根据这个方法的名字大概就能猜到这个方法的用途了。但是这个方法在1.6里面被标记成
deprecated的了。被$$和Eelement.select方法代替了,关于这两个方法,后面在讲。
$R就是简历ObjectRange对象的便捷方法,关于ObjectRange对象具体参考【Prototype 学习——ObjectRange对象 】
Try.these:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.
//就是用一个循环嵌套try...catch完成这个工具函数的 var Try = { these: function() { var returnValue; for (var i = 0, length = arguments.length; i < length; i++) { var lambda = arguments[i]; try { returnValue = lambda(); break; } catch (e) { } } return returnValue; } };
看一个例子(不同的浏览器有不同的创建XMLHttpRequest的方法):
getTransport: function() { return Try.these( function() { return new XMLHttpRequest() }, function() { return new ActiveXObject('Msxml2.XMLHTTP') }, function() { return new ActiveXObject('Microsoft.XMLHTTP') } ) || false; }
document.getElementsByClassName():
根据这个方法的名字大概就能猜到这个方法的用途了。但是这个方法在1.6里面被标记成
deprecated的了。被$$和Eelement.select方法代替了,关于这两个方法,后面在讲。
相关文章推荐
- Prototype 1.6 边学边译 -- 工具函数 document.getElementsByClassName
- 解决 IE 不支持 document.getElementsByClassName() 的方法
- 根据原生JS封装函数,根据传递的选择器查找对应的元素以及解决getElementsByClassName() 兼容问题
- javascript getElementsByClassName函数
- js中获取类名的函数getElementsByClassName()
- document.getElementsByClassName的理想实现
- document.getElementsByClassName的封装,兼容ie8
- document.getElementsByClassName在ie8及其以下浏览器的兼容性问题
- IE不兼容document.getElementsByClassName
- document.getElementsByClassName 兼容性
- document.getElementsByClassName在ie8及其以下浏览器的兼容性问题
- getElementsByClassName函数的兼容写法
- 原生js方法document.getElementsByClassName在ie8及其以下的兼容性问题
- document.getElementById与getElementsByClassName的区别
- IE8以下浏览器不支持document.getElementsByClassName() 访问节点;怎么解决?---封装自己的类名
- document.getElementsByClassName在ie8及其以下浏览器的兼容性问题
- js document.getElementsByClassName的使用介绍与自定义函数
- ie8及其以下浏览器的document.getElementsByClassName兼容性问题
- 原生js document.getElementsByClassName在IE8及以下浏览器的兼容
- document.getElementsByClassName的理想实现