返回到:Prototype – 实用方法
$R() 函数只是编写 new ObjectRange(lowerBound, upperBound, excludeBounds) 的简写。
语法
$R(start, end[, exclusive = false]);
这里,start是范围的起始元素,end是范围的最后一个元素。如果exclusive flag设置为false,那么它会包含结束元素,否则不会包含在范围内。
返回值
范围对象。
例子
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function ShowValues() {
var range = $R(10, 20, false);
range.each(function(value, index) {
alert(value);
});
}
</script>
</head>
<body>
<p>Click "Show Value" button to see the result</p>
<form>
<input type = "button" value = "Show Value" onclick = "ShowValues();"/>
</form>
</body>
</html>更多例子
以下语句返回true值
$R(0, 10).include(10);
以下语句返回字符串“0、1、2、3、4、5”
$A($R(0, 5)).join(', ');
以下语句返回一个字符串“aa, ab, ac, ad, ae, af, ag, ah”
$A($R('aa', 'ah')).join(', ');
以下声明返回false
$R(0, 10, true).include(10);
对于值 = 0 到 9,以下语句将被调用 10 次
$R(0, 10, true).each(function(value) {
// invoked 10 times for value = 0 to 9
});返回到:Prototype – 实用方法
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8945.html
支付宝
微信