- Prototype 教程
- Prototype - 主頁
- Prototype - 簡要概述
- Prototype - 有用功能
- Prototype - 實用方法
- Prototype - 元素物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - 雜湊處理
- Prototype - 基本物件
- Prototype - 模板
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - 表示範圍
- Prototype - 定期間隔執行
- Prototype 有用資源
- Prototype - 快速指南
- Prototype - 有用資源
- Prototype - 討論
原型 - $R() 方法
$R() 函式僅僅是 new ObjectRange(lowerBound, upperBound, excludeBounds) 的簡寫。
語法
$R(start, end[, exclusive = false]);
此處,start 是範圍的起始元素,end 是範圍的最後一個元素。如果將排他標誌設定為 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_utility_methods.htm
廣告