prototypeの中のドル関数の使い方
この$はかなり役に立ちます.例から多くのコードを省くことができます.
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Untitled Document</title>
- <script src="prototype.js"></script>
- <script>
- //$$ Javascript getElementByTagName
- function _$$Test(){
- var _$$ = $$('input');
- for(i=0;i<_$$.length;i++){
- alert(_$$[i].value);
- }
-
- //$$()
- var f = $$('div #testForm.field input');
- var s = '';
- for(var i=0; i<f.length; i++){
- s += f[i].value + '/';
- }
- alert(s);
-
- f = $$('div#testForm.field input', 'div#testForm.fieldName');
- s = '';
- for(var i=0; i<f.length; i++){
- s += ( f[i].value ? f[i].value : f[i].innerHTML ) + '/';
- }
- alert(s);
- }
- </script>
- </head>
- <body>
- <div id="testForm">
- <div class='field'>
- <span class='fieldName'>User name:</span>
- <input type='text' id='txtName' value='sucre'/>
- </div>
- <div class='field'>
- <span class='fieldName'>Password:</span>
- <input type='password' id='txtPass' value='secret' />
- </div>
- <input type='submit' value='login' />
- </div>
- <input type="text" value=" "/>
- <input type="hidden" value=" "/>
- <input type="radio" value=" "/>
- <input type="checkbox" value=" "/>
- <input type="button" value="GO" onclick="_$$Test()"/>
- </body>
- </html>
Javascriptを再度包装します.いいです.使いやすいです.