<script src="prototype.js"></script>
<script>
/*var arr = [1,2,3,4,8,5,4,3];
// 依次输出1,2,3,4,5,4,3
arr.each(
function (item, index) {
if (item < 6) {
alert(item);
} else {
throw $continue;
}
}
);
// 依次输出1,2,3,4
arr.each(
function (item, index) {
if (item < 6) {
alert(item);
} else {
throw $break;
}
}
);*/
/*
var arr = [1,2,3,4,5];
// arr = [1,2,3,4,5]
arr.reverse(false);
alert(arr.inspect());
// arr = [5,4,3,2,1]
arr.reverse();
alert(arr.inspect());
var arr = [1,2,3,4,5];
arr.reverse();
// 返回2在arr中的序号:1
var index = arr.indexOf(2);
alert(index)
var arr = [1,2,3,4,5];
// 不包含2和4,返回[1,3,5]
var newArr = arr.without(2,4);
alert(newArr.inspect());
var arr = [1,2,3,4,5];
arr.clear();
alert(arr[2]);
var arr = [1,2,3,4,5];
var arr2 = [2,4,6,8,10];
//[ [1,2],[2,4],[3,6],[4,8],[5,10]]
var newArr = arr.zip(arr2);
// [[1,4],[4,16],[9,36],[16,64],[25,100]]
var newArr2 = arr.zip(
arr2,
function (item) {
var newItem = item.collect(
function (item, index) {
return item * item;
}
);
return newItem;
}
);
alert(newArr.inspect());
alert(newArr2.inspect());
var arr = [5,2,3,1,4];
// 将arr排序
var arr = arr.sortBy(
function (item, index) {
return item;
}
);
arr.each(
function (item, index) {
alert(item);
}
);
var arr = [
{root: 1, square: 1},
{root: 2, square: 4},
{root: 3, square: 9},
{root: 4, square: 16},
{root: 5, square: 25}
];
var newArr = arr.pluck("square");
alert(newArr[4]);
var arr = [1,2,3,4,5];
var ptArr = arr.partition(
function (item, index) {
return item%2 == 1;
}
);
var oddArr = ptArr[0];
var evenArr = ptArr[1];
oddArr.each(
function (item) {
alert(item);
}
);
evenArr.each(
function (item) {
alert(item);
}
);
var arr = [1,2,3,4,5];
// 最大值
var max = -arr.min(
function (item, index) {
return -item;
}
);
// 最小值
var min = arr.min();
alert(max);
alert(min);
var arr = [1,2,3,4,5];
// 最大值
var max = arr.max();
// 最小值
var min = -arr.max(
function (item, index) {
return -item;
}
);
alert(max);
alert(min);
// 求集合中每一个元素的平方
Number.prototype.square = function () {
return this * this;
}
var arr = [1,2,3,4,5];
var newArr = arr.invoke("square");
alert(newArr[4]);
// 计算arr中所有数的乘积
var factorial = arr.inject(
1,
function (accumulator, item, index) {
return accumulator * item;
}
);
alert(factorial)
// 判断集合中是否包含”2“
var inc = arr.include(2);
alert(inc);
var arr = ["12345", "abc2", "cde", "fgh", "132ba"];
var newArray = arr.grep(
/2/,
function (item, index) {
return item + " contains 2";
}
)
newArray.each(
function (item) {
alert(item);
}
);
var arr = [1,2,3,4,5];
// 返回集合中所有的奇数
var oddArr = arr.findAll(
function (item, index) {
return item%2 == 1;
}
);
alert(oddArr[2]);
// 返回第一个大于3的元素
var ele = arr.find(
function (item, index) {
return (item > 3);
}
);
alert(ele);
var newArr = arr.collect(
function (item, index) {
return item * (index + 1);
}
);
var hasNegative = arr.any(
function (item, index) {
return (item < 0);
}
);
// 测试集合中的所有元素是否大于0
var allPositive = arr.all(
function(item, index) {
return (item > 0);
}
)
alert(allPositive);
arr.each(
function (item, index) {
alert("arr[" + index + "] = " + item);
}
);*/
</script>
没有合适的资源?快使用搜索试试~ 我知道了~
prototypejs和例子代码
共58个文件
html:24个
gif:10个
jpg:9个
需积分: 8 29 下载量 147 浏览量
2008-06-20
14:17:24
上传
评论
收藏 249KB RAR 举报
温馨提示
prototype1.4.js和prototype1.5.js,以及一些例子代码<br>
资源推荐
资源详情
资源评论
收起资源包目录
Demo.rar (58个子文件)
Demo
Quick guide to somewhat advanced JavaScript.files
recommendations.css 475B
1932394613.01._AA_SCTZZZZZZZ_.jpg 3KB
link-enhancer 11KB
ir(1).gif 42B
articles.css 2KB
ir.gif 42B
noscript.gif 42B
0764579088.01._AA_SCTZZZZZZZ_.jpg 4KB
Quick guide to somewhat advanced JavaScript.htm 16KB
JSON创建pet.HTML 878B
index_04.jpg 49KB
prototype1.5.1RC2.js 94KB
Template.HTML 640B
ObjectRange.HTML 447B
prototype.js 92KB
Array.HTML 3KB
自己动手实现.html 616B
loading2.gif 11KB
Event.observe.html 598B
微软Ajax脚本库
MicrosoftAjaxWebForms.js 63KB
MicrosoftAjax.js 222KB
MicrosoftAjaxTimer.js 5KB
Ajax.HTML 926B
$test.html 861B
Using prototype_js v1_5_0.files
recommendations.css 475B
0321385551.01._SL110_SCTZZZZZZZ_.jpg 3KB
1932394613.01._AA_SCTZZZZZZZ_.jpg 3KB
link-enhancer 11KB
ir(4).gif 42B
prot_ref.css 3KB
ir(1).gif 42B
0321237706.01._SL110_SCTZZZZZZZ_.jpg 4KB
0974514055.01._AA_SCTZZZZZZZ_.jpg 3KB
ir(3).gif 42B
ir(2).gif 42B
ir.gif 42B
0764579088.01._AA_SCTZZZZZZZ_.jpg 4KB
Ajax2.html 609B
DOM.Insertion.HTML 303B
$$Test.HTML 1KB
Form.Element.Observer.html 1KB
Hash.HTML 401B
$test1.html 794B
Ajax3.html 1KB
$Rtest.html 822B
script.html 269B
script1.html 196B
$Ftest.html 543B
Dom.html 770B
$Atest.html 943B
Base.html 3KB
Prototype1.4.js 59KB
200607061129268fc45.jpg 17KB
Using prototype_js v1_5_0.htm 164KB
$H.html 594B
Ajax4.html 727B
String Test.htm 3KB
loading.gif 878B
共 58 条
- 1
资源评论
dsj188
- 粉丝: 34
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功