希望大家踊跃发言  社会需要思路清晰 短小精悍 的经典代码 (注意 不是网上流传的那种一句话代码)
要让人看过之后 心情舒畅  大呼过瘾的代码 心里要很崇拜的想着:原来代码也可以这样的
RT

解决方案 »

  1.   

    比如alert("哦耶,过瘾啊!");  //这代码思路清晰,短小精悍,经典,看过之后心情舒畅,大呼过瘾
      

  2.   

    活跃一下气氛...有利于抛砖引玉...顺便把帖子顶上去嘛~~那我先来说一个有价值点的吧...function $(id){return document.getElementById(id);}
    function $$(tag){return document.getElementsByTagName(tag);}
      

  3.   

    最新研究成果:图片无缝滚动
    <div id="b1" style="position:absolute; white-space:nowrap;overflow:hidden;z-index:1; background-color:#FFFFFF;border:solid 1px #00FF00;width:400px;height:120px;left:120;top:100;" >
      你好1555555555555555555
      <img src="1.jpg" onload="PicZoomByHeight(this);" style="height:100px;border:solid 1px #999999"/>
      <img src="2.jpg" onload="PicZoomByHeight(this);" style="height:100px;border:solid 1px #999999"/>
      <img src="3.jpg" onload="PicZoomByHeight(this);" style="height:100px;border:solid 1px #999999"/>
    </div>
    <script>
      function marqueeGood()
      {
        if(b1.scrollLeft>=b1.scrollWidth/2+2)  //如果滚动到等同初始视图的位置,再从新滚动,防闪烁;  +2修正值,一般不需要再调整.
      b1.scrollLeft=0;                     
    else
          b1.scrollLeft++;                     //如果层内容过少,导致scrollLeft即使++也不再变化,不能进入上面复位代码.导致停止滚动.
    marqID=setTimeout(marqueeGood,10);
      }
      var marqID=setTimeout(marqueeGood,10);
      b1.innerHTML=b1.innerHTML+b1.innerHTML;
      b1.onmouseover=function(){
        clearTimeout(marqID);
      }
      b1.onmouseout=function(){
        marqID=setTimeout(marqueeGood,10);
      }
      if(b1.style.posWidth>b1.scrollWidth/2) alert('无缝滚动:内容如果过少,可能无法连续滚动.请添加内容或减少层宽');
    </script><script>
       function PicZoomByHeight(el)   
       {
         //以高度优先相等为准则.   对宽度不是很敏感
     var imgx=new Image();
     imgx.src=el.src;
     var fRate=imgx.height*1.0 /el.style.posHeight;
         this.style.width=imgx.width*1.0/fRate;
       } 
    </script>
      

  4.   


    <scrīpt type=text/javascrīpt>
    var pic_width=326; //图片宽度
    var pic_height=217; //图片高度
    var button_pos=4; //按扭位置 1左 2右 3上 4下
    var stop_time=3000; //图片停留时间(1000为1秒钟)
    var show_text=0; //是否显示文字标签 1显示 0不显示
    var txtcolor="000000"; //文字色
    var bgcolor="DDDDDD"; //背景色
    var imag=new Array();
    var link=new Array();
    var text=new Array();
    imag[1]="images/01.jpg";
    link[1]="#";
    text[1]="标题 1";
    imag[2]="images/02.jpg";
    link[2]="#";
    text[2]="标题 2";
    imag[3]="images/03.jpg";
    link[3]="#";
    text[3]="标题 3";
    imag[4]="images/04.jpg";
    link[4]="#";
    text[4]="标题 4";
    imag[5]="images/05.jpg";
    link[5]="#";
    text[5]="标题 5";
    //可编辑内容结束
    var swf_height=show_text==1?pic_height+20:pic_height;
    var pics="", links="", texts="";
    for(var i=1; i<imag.length; i++){
     pics=pics+("|"+imag[i]);
     links=links+("|"+link[i]);
     texts=texts+("|"+text[i]);
    }
    pics=pics.substring(1);
    links=links.substring(1);
    texts=texts.substring(1);
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0" width="'+ pic_width +'" height="'+ swf_height +'">');
    document.write('<param name="movie" value="images/focus.swf">');
    document.write('<param name="quality" value="high"><param name="wmode" value="opaque">');
    document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">');
    document.write('<embed src="images/focus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowscrīptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
    </scrīpt>
      

  5.   

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <body></body>
    <style>
    *{border:1px solid green}
    a{display:block;font-size:15px}
    </style>
    <div id="d" style="width:300px;height:200px;">
    <a href="javascript:">1,你可曾有过无数的梦想,</a>
    <a href="javascript:">2,却在时光的流逝里幻灭 </a>
    <a href="javascript:">3,你可曾对未来期待憧憬,</a>
    <a href="javascript:">4,却在成长的岁月中迷失</a>
    </div> 
    <script>
    var d=document.getElementById("d")
    var t=setInterval(myfunc,1000)
    function myfunc(){ d.appendChild(d.firstChild)}
    d.onmouseover=function(){clearInterval(t)}
    d.onmouseout=function(){t=setInterval(myfunc,1000)}
    </script>
      

  6.   

    不经典 但是是原创
    <body></body>
    <script>
     function create(elm,parent,fn){var element = document.createElement(elm);fn&&fn(element);parent.appendChild(element);};
     create('div',document.body,function(elm){
     with(elm.style){
      width=height= "100px";border = "1px solid #FF0000";
     }
     })
     create('input',document.body,function(elm){
     with(elm){
     type = 'button';value='确定';
     }
     })
    </script>
      

  7.   

    转:
    在一个带有图片的网页,把下面代码贴到浏览器地址栏回车看效果javascript:R=0;x1=.1;y1=.05;x2=.25;y2=.24;x3=1.6;y3=.24;x4=300;y4=200;x5=300;y5=200;DI=document.getElementsByTagName('img');DIL=DI.length;function A(){for(i=0;i-DIL;i++){DIS=DI[i].style;DIS.position='absolute';DIS.left=Math.cos(R*x1+i*x2+x3)*x4+x5+'px';DIS.top=Math.sin(R*y1+i*y2+y3)*y4+y5+'px';}R++;}setInterval('A()',5);void(0); 
      

  8.   

    JavaScript精华代码库http://www.jslab.org.cn
      

  9.   

    alert("你牛逼,我崩溃!"); 
      

  10.   

    <a href="#" onclick="return confirm('确定要删除这条数据吗?')">删除</a>;
      

  11.   

    <html>
    <head></head>
    <body>
    <form action="test.html" method="post">
    <select onchange="javascript:document.forms[0].submit();">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    <input type='submit' value="submit">
    </form>
    </body>
    </html>
      

  12.   

    我写一个计算阶乘的!<script language="javascript" type="text/javascript">
    var a = (function(n){if(n<1){alert('invalid argument!');return;} else if(n==1){return 1;}else{return n * arguments.callee(n-1)}})(4);
    alert(a);
    </script>
      

  13.   

    if(i===0){
       alert(1);
    }
    if(j!==0){
       alert(2)
    }
    注意,上面的代码,我没写错!我相信有很大一部分人不知道===和!==的意思,不知道的去baidu上搜搜吧
      

  14.   

    没有好东西,发大伙都知道的几个常用函数 var $ = function(sId){
    return "string" == typeof sId ? document.getElementById(sId) : sId;
    }; var isIE = /MSIE (\d)\./.test(window.navigator.userAgent); var isIE6 = isIE && (RegExp.$1 == 6); var Extend = function(distination, source){
    for(var property in source){
    distination[property] = source[property];
    }
    return distination;
    }; var Bind = function(object, fun){
    return function(){
    fun.apply(object, arguments);
    }
    }; var addEvent = function(a, b, c, d) {
    if(a.attachEvent) a.attachEvent(b[0], c);
    else a.addEventListener(b[1] || b[0].replace(/^on/,""), c, d || false);
    return c;
    }; var delEvent = function (a, b, c, d) {
    if (a.detachEvent) a.detachEvent(b[0], c);
    else a.removeEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
    return c;
    }; var BindAsEventListener = function(object, fun) {
    var args = Array.prototype.slice.call(arguments).slice(2);
    return function(event) {
    return fun.apply(object, [event || window.event].concat(args));
    }
    }; var SetStyle = function(el, n, v) {
    if (!el) return;
    if (typeof n == "object"){for(var i in n) SetStyle(el, i, n[i]);return;}
    if (el instanceof Array) {for(var i = el.length - 1; i >=0; i--) SetStyle(el[i], n, v);return;}
    el.style[n] = v;
    };
      

  15.   

    http://www.scriptlover.com/controls/
      

  16.   

    这个最经典,学习任何语言的第一句代码alert("hello world")