佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 802|回复: 1

Prototype.js 1.5推出了

[复制链接]
发表于 27-1-2007 10:12 AM | 显示全部楼层 |阅读模式
如果你还不知道prototype.js这个冬冬的存在,你一定要看看。Prototype.js是一个javascript framework,利用它来编写你的js程式码,将会事半功倍。Prototype.js强化了js的许多类型,包括DOM Element,Array,String,Number,Enumerable,class等等,还加入了Ajax物件。还有,如果你接触过Ruby的话,你会惊喜地发现编写Javascript就好像在编写Ruby这样,程式码可以很简捷。来看看下面的例子:


  1. <#String>


  2. "chinese-cari".camelize(); -> "chineseCari"

  3. "<script>4+2</script>".evalScript(); -> [6]

  4. "Hello World!".gsub("!"," Cari!"); -> "Hello World Cari!"

  5. <#Array>

  6. ["david","alan","bill","steve"].each(function(name){
  7.   alert(name);
  8. });

  9. ["dave",["david","alan",["alan"]],"Lawrence"].flatten(); ->["dave","david","alan","alan","Lawrence"]

  10. <#Hash>

  11. var myHash = new Hash({
  12. name:"Michael",
  13. occupation:"Doctor",
  14. age:13
  15. });

  16. myHash["name"]; -> "Michael"

  17. myHash.keys(); ->["name","occupation","age"]

  18. myHash.toQueryString(); -> "name=Michael&occupation=Doctor&age=13"

  19. <Function>
  20. //binding object function
  21. var obj = {
  22.   name:"David",
  23.   fx:function(){
  24.      alert(this.name+", "+arguments[0]);
  25.   }
  26. }

  27. var fx2 = obj.fx.bind(obj);
  28. fx2("Nice to meet you!"); -> "David, Nice to meet you!"

  29. <Element>

  30. $('test') equivalent to document.getElementById('test')

  31. $('special') <-- css class element collector. get all element with class name 'special'

  32. $A($('special')) <-- cast the element collection into Enumerable, can access to most of the enumerable methods

  33. ["div1","div2","div3"].each(Element.hide); <-- set the style of display to "none" of all the elements with id in the array

  34. <Ajax!!>

  35. URL = 'http://www.google.com/search?q=Prototype';
  36. new Ajax.Request('/proxy?url=' + encodeURIComponent(URL), {
  37.   method: 'get',
  38.   onSuccess: function(transport) {
  39.     var notice = $('notice');
  40.     if (transport.responseText.match(/<a class=l href="http:\/\/prototypejs.org/))
  41.       notice.update('Yeah!  You are in the Top 10!').setStyle({ background: '#dfd' });
  42.     else
  43.       notice.update('Damn!  You are beyond #10...').setStyle({ background: '#fdd' });
  44.   }
  45. });
复制代码


更多说明,参考prototype.js的API Doc

http://prototypejs.org/api/

回复

使用道具 举报


ADVERTISEMENT

发表于 27-1-2007 06:47 PM | 显示全部楼层
好像很少人董。

我也不懂有这样好的东西

等下去看看

吃饭先
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 27-8-2025 09:45 AM , Processed in 0.110007 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表