编程人员对于JQuery框架性能评论说明

JQuery框架是JavaScript语言的一个新的资源库 ,它***的性能:快速,简洁的使用HTML documents, handle events, perform animations,而且还可以能把Ajax交互应用到网页,这样就能够改变你书写的方式与格式。

现在有好多比较优秀的客户端脚本语言组件, 如: Prototype、YUI、jQuery、mootools、Bindows, Scriptaculous, FCKEditor 等, 都非常不错, 最近研究了一下 jQuery,在学习时顺便整理了一个教程, 后面会有示例代码下载链接. #t#

1. 访问页面元素

 
 
  1.  runat="server"> 
  2.  2     </strong>访问元素<strong> 
  3.  3      src=Resources\js\jquery-1.2.1.js type="text/javascript">   
  4.  4          
  5.  5          type="text/javascript"> 
  6.  6         function GetElement()  
  7.  7         {  
  8.  8             //通过ID获取元素TextBox1的客户端Dom对象                          
  9.  9             tb = $("#<%= TextBox1.ClientID %>")[0];       //1. 通过索引获取Dom对象      
  10. 10             tb = $("#<%= TextBox1.ClientID %>").eq(0)[0]; //2. 通过eq, eq(0)获取的是JQuery对象, 再通过索引获取Dom对象.  
  11. 11             tb = $("#<%= TextBox1.ClientID %>").get(0);   //3. 通过get方法获取Dom元素              
  12. 12             alert(tb.value);  
  13. 13               
  14. 14             //通过class属性获取元素的客户端Dom对象                          
  15. 15             div1 = $(".KingClass")[0];              
  16. 16             alert(div1.innerText);  
  17. 17               
  18. 18             //通过Html标签获取元素的客户端Dom对象                          
  19. 19             div1 = $("div")[1];              
  20. 20             alert(div1.innerText);        
  21. 21         }  
  22. 22      
  23. 23  
  24. 24  
  25. 25      id="form1" runat="server"> 
  26. 26     
     
  27. 27          ID="TextBox1" runat="server" Text="Hello! ChengKing."> 
  28. 28          class="KingClass">Hello! Rose
  /> 
  • 29          type = button value="获取元素" onclick = "GetElement();" /> 
  • 30     
  •  
  • 31      
  • 32  
  • 2. Dom对象和JQuery框架转换示例

     
     
    1.  runat="server"> 
    2.  2     </strong>Dom和jQuery对象转换示例<strong> 
    3.  3      src=Resources\js\jquery-1.2.1.js type="text/javascript">   
    4.  4          
    5.  5          type="text/javascript"> 
    6.  6         function ChangeObjectType()  
    7.  7         {  
    8.  8             //调用Dom对象方法                         
    9.  9             tb_dom = document.getElementById('<%= div1.ClientID %>');  
    10. 10             alert(tb_dom.innerHTML);  
    11. 11               
    12. 12             //用$方法把Dom对象转换为jQuery对象, 再调用jQuery对象方法  
    13. 13             tb_jQuery = $(tb_dom);   
    14. 14             alert(tb_jQuery.html());  
    15. 15               
    16. 16             //取jQuery对象中的Dom对象  
    17. 17             tb_dom2 = tb_jQuery[0];  
    18. 18             alert(tb_dom2.innerHTML);           
    19. 19              
    20. 20         }  
    21. 21      
    22. 22  
    23. 23  
    24. 24      id="form1" runat="server"> 
    25. 25     
       
    26. 26          id="div1" runat=server> 
    27. 27             Hello! ChengKing.  
    28. 28         
     
  • 29          type = button value="对象转换" onclick = "ChangeObjectType();" /> 
  • 30      
  • 31      
  • 32  
  • 3. 访问对象内部元素

     
     
    1.  runat="server"> 
    2.  2     </strong>访问内部元素<strong> 
    3.  3      src=Resources\js\jquery-1.2.1.js type="text/javascript">   
    4.  4          
    5.  5          type="text/javascript"> 
    6.  6         function VisitInnerElement()  
    7.  7         {         
    8.  8             //取得Div中第二个P元素       
    9.  9             p = $("#<%= div1.ClientID %> P").eq(1); //等号左边的p对象为p对象集合             
    10. 10             alert(p.html());  
    11. 11               
    12. 12             //取得Div中***个P元素  
    13. 13             p = $("#<%= div1.ClientID %> P:first").eq(0); //first为关键字             
    14. 14             alert(p.html());  
    15. 15               
    16. 16             //取得Div中第二个P元素  
    17. 17             p = $("#<%= div1.ClientID %> P:last").eq(0);  //last为关键字           
    18. 18             alert(p.html());  
    19. 19              
    20. 20         }  
    21. 21      
    22. 22  
    23. 23  
    24. 24      id="form1" runat="server"> 
    25. 25     
       
    26. 26          id="div1" runat=server>              
    27. 27             

      Hello! ChengKing.

              
    28. 28             

      Hello! Rose.

          
    29. 29          
    30. 30          type = button value="访问内部元素" onclick = "VisitInnerElement();" /> 
    31. 31      
    32. 32      
    33. 33  

    分享标题:编程人员对于JQuery框架性能评论说明
    分享网址:http://www.hantingmc.com/qtweb/news23/381273.html

    网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

    广告

    声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联