这个$$相当有用,从例子中可以发现省去好多的代码
- <!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重新封装,不错,好用
本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/410373,如需转载请自行联系原作者