Advertisement
Guest User

Untitled

a guest
Aug 15th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. </head>
  4. <input type=text value=xxx>
  5. <script type="text/javascript">
  6. if (!('forEach' in Array.prototype)) {
  7.     Array.prototype.forEach= function(action, that /*opt*/) {
  8.         for (var i= 0, n= this.length; i<n; i++)
  9.             if (i in this)
  10.                 action.call(that, this[i], i, this);
  11.     };
  12. }
  13. if (!('map' in Array.prototype)) {
  14.     Array.prototype.map= function(mapper, that /*opt*/) {
  15.         var other= new Array(this.length);
  16.         for (var i= 0, n= this.length; i<n; i++)
  17.             if (i in this)
  18.                 other[i]= mapper.call(that, this[i], i, this);
  19.         return other;
  20.     };
  21. }
  22.  
  23. function getAllElements() {
  24.    var elements = [];
  25.    ['input','select'].forEach(function (nodeName) {
  26.        elements.push.apply(elements , document.getElementsByTagName(nodeName));
  27.    });
  28.    return elements;
  29. }
  30.  
  31. document.onclick=new function(){
  32. var buff = getAllElements().map(function (el) {
  33.         return el.name;
  34.     }).join();
  35.     alert(buff);
  36.      }
  37. }
  38.  
  39. </script>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement