天天看點

解析jQuery的鍊式程式設計

<!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 type=text/javascript charset=utf-8 src="../commons/jquery.js" ></script>

 </head>

 <body>

  <input id="inp" type="button" value="點選我" />

  <script type=text/javascript charset=utf-8>

    // 模拟jquery底層鍊式程式設計

    $.onReady(function(){

     var inp = $('#inp');

     //alert(inp.dom.nodeName);

     //alert($('#inp'));

     inp.addEvent('click',function(){

      alert('我被點選了!');

     }).setStyle('backgroundColor' , 'red');

    });

  </script>  

 </body>

</html>

繼續閱讀