返回到:Prototype – 实用方法
$R() 函数只是编写 new ObjectRange(lowerBound, upperBound, excludeBounds) 的简写。
语法
$R(start, end[, exclusive = false]);
这里,start是范围的起始元素,end是范围的最后一个元素。如果exclusive flag设置为false,那么它会包含结束元素,否则不会包含在范围内。
返回值
范围对象。
例子
HTML
x
25
25
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function ShowValues() {
8
var range = $R(10, 20, false);
9
10
range.each(function(value, index) {
11
alert(value);
12
});
13
}
14
</script>
15
</head>
16
17
<body>
18
<p>Click "Show Value" button to see the result</p>
19
20
<form>
21
<input type = "button" value = "Show Value" onclick = "ShowValues();"/>
22
</form>
23
24
</body>
25
</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 – 实用方法
阅读剩余 55%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8945.html