ææ°ã 1.5.0_pre1 ã«ãªã£ã¦ãã®ã§èª¿æ»
Prototype.js 1.5.0_pre0 ããã®å¤æ´ç¹
CHANGELOG ãã
- Selector åã³ $$ ãå±æ§ã»ã¬ã¯ã¿ã«å¯¾å¿ã
- Ajax éä¿¡æã® HTTP ãããã追å ã
- $$ ã IE ã§ãåãããã«ããã
- Element.extend ã追å ã
- Element.replace ã追å
- Enumerable.zip ã®ãã°ãã£ãã¯ã¹
Selector
Selector ã«å±æ§ã»ã¬ã¯ã¿ã追å ããããå±æ§ã»ã¬ã¯ã¿ã¨ã¯ CSS 2.0 ããå°å ¥ãããå±æ§ãé¸ææ¡ä»¶ã¨ããã»ã¬ã¯ã¿ã§ããã
ä¾
Event.observe(window, 'load', function() { var selector; var elements; // style å±æ§ãæã¤è¦ç´ ãåå¾ãçµæãããããã selector = new Selector('input[style]'); elements = selector.findElements(document); elements.each(function(elem) { alert(elem.value) }); // type="button" å±æ§ãæã¤è¦ç´ ãåå¾ãçµæããã selector = new Selector('input[type="button"]'); elements = selector.findElements(document); elements.each(function(elem) { alert(elem.value) }); // type="button" å±æ§ãæããªãè¦ç´ ãåå¾ãçµæãããããã selector = new Selector('input[type!="button"]'); elements = selector.findElements(document); elements.each(function(elem) { alert(elem.value) }); // class å±æ§ãåè§ã¹ãã¼ã¹åºåãã«ã㦠className01 ãå«ãè¦ç´ ãåå¾ãçµæããã selector = new Selector('input[class~="className01"]'); elements = selector.findElements(document); elements.each(function(elem) { alert(elem.value) }); // class å±æ§ãåè§ãã¤ãã³åºåãã«ã㦠class ãå«ãè¦ç´ ãåå¾ãçµæããã selector = new Selector('input[class|="class"]'); elements = selector.findElements(document); elements.each(function(elem) { alert(elem.value) }); // è¤æ°ã®å±æ§ã»ã¬ã¯ã¿ãæå®ãããã¨ãã§ããã // style å±æ§ class å±æ§ãæã¤è¦ç´ ãåå¾ãçµæããã selector = new Selector('input[style][class]'); elements = selector.findElements(document); elements.each(function(elem) { alert(elem.value) }); });
<body> <div> <input value="ã" type="text" class="className01 className02"/> <input value="ã" type="button" style="background-color:white;" /> <input value="ã" type="submit" class="class-name-03" style="background-color:white;" /> </div> </body>
ä¸ã®ä¾ã 1.5.0_pre0 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-00.html
ä¸ã®ä¾ã 1.5.0_pre1 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-01.html
$$
Selector ã¨åæ§ã«å±æ§ã»ã¬ã¯ã¿ã追å ããããå±æ§ã»ã¬ã¯ã¿ã¨ã¯ CSS 2.0 ããå°å
¥ãããå±æ§ãé¸ææ¡ä»¶ã¨ããã»ã¬ã¯ã¿ã§ããã
詳ããã¯ä¸ãåç
§ã
ä¾
Event.observe(window, 'load', function() { var elements = $$('div div[class="a"] div[class="a"]'); elements.each(function(elem) { alert(elem.innerHTML); }); });
<body> <div> <div> <div>ã</div><div>ã</div><div>ã</div> </div> <div class="a"> <div>ã</div><div class="a">ã</div><div>ã</div> </div> <div> <div>ã</div><div>ã</div><div>ã</div> </div> </div> </body>
ä¸ã®ä¾ã 1.5.0_pre0 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-10.html
ä¸ã®ä¾ã 1.5.0_pre1 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-11.html
Ajax.Request
Ajax ç³»ã®éä¿¡æã®ãªã¯ã¨ã¹ããããã® Accept ã text/javascript, text/html, application/xml, text/xml, */* ã«ããã
ä¾
new Ajax.Request( '/xml/20060327.xml', { method : 'get', onSuccess : function(req){ var doc = req.responseXML; alert(doc.documentElement.firstChild.nodeValue); } } );
<?xml version="1.0" encoding="utf-8"?> <content>ããã«ã¡ãï¼</content>
ä¸ã®ä¾ã 1.5.0_pre0 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-20.html
ä¸ã®ä¾ã 1.5.0_pre1 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-21.html
ãããç£è¦ãã¼ã«ã§ç¢ºèªãã¦ãã ããã
Element.extend
Element.setStyle ã Element.update ãªã©ã®æ§ã
ãªé¢æ°ã使ããããã«ãªããããªã便å©ï¼
$ é¢æ°ã document.getElementsByClassName é¢æ°ã $$ é¢æ°ã®çµæ㯠Element.extend ã«ãã£ã¦ Element ã®é¢æ°ãç¹ãè¾¼ã¾ããç¶æ
ã§å¾©å¸°ãããã
ï¼ã¢ãã¡ã¼ã·ã§ã³ã¨ãããå ´åãã«ã¼ãä¸ã«ããå ´å㯠$ é¢æ°ãéããªãã®ã§å½±é¿ã«æ³¨æï¼
ä¾
Event.observe(window, 'load', function() { var element = document.body; Element.extend(element); element.update('ããã«ã¡ãï¼'); element.setStyle({ 'color': 'red' }); });
ä¸ã®ä¾ã 1.5.0_pre0 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-30.html
ä¸ã®ä¾ã 1.5.0_pre1 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-31.html
Element.replace
è¦ç´ ãæååã§ç½®æããã
ã½ã¼ã¹ã®è©±ãã ã outerHTML ããªãç°å¢ã§ã® createRange ã使ã£ãç½®æãèå³æ·±ãã
ä¾
Event.observe(window, 'load', function() { $$('span')[0].replace('ã°ãã'); });
<body> <div>ãã<span>ã«ã¡ã</span></div> </body>
ä¸ã®ä¾ã 1.5.0_pre0 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-40.html
ä¸ã®ä¾ã 1.5.0_pre1 ã§å®è¡â http://Sample.ECMAScript.jp/20060327-41.html