一些应该熟记于心的jQuery函数和技巧

发表于:2011-1-19 10:00

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:司马牵牛 译    来源:51Testing软件测试网采编

  • $(document).ready(function(){  
  •     //Allthehiddenimagesareshown  
  •     $("img:hidden").show();         
  • //Thefirstpisgoingtobeorange  
  •      $("p:first").css("color","orange");  
  •  //Inputwithtypepassword  
  •    //thisis$("input[type='password']")  
  •     $("input:password").focus(function(){  
  •        alert("Thisisapassword!");  
  •      });                    
  •  //Divswithparagraph  
  •      $("div:has(p)").css("color","green");  
  • //Wecanalsocombinethem.with()  
  •      //Allnotdisabledcheckboxes  
  •      $("input:checkbox(:not(:disabled))").hover(function(){  
  •         alert("Thischeckboxisworking.");  
  •      });   
  •   });
  •   如上例所示,可供使用的选择器是多种多样的,并且它们之前不是互相独立的,所以我们可以将这些选择器组合起来进行使用,如上例中的选择器。

      理解网站的结构

      网络的结构可能看起来非常复杂,但事实上并非如此,如果我们想要使用某些选择器以及作用于网络结构之上的方法。我们可以将网站视为一个颠倒的树,树根在顶部,而其他元素从根部延伸出来。查看下面的代码,试着想象一棵树,树根是body标签。

  • <html xmlns="http://www.w3.org/1999/xhtml"> 
  • <head>...</head> 
  • <body> 
  •     <div id="wrapper"> 
  •         <div id="main"> 
  •             <h1>CreateanAccount!</h1> 
  •             <form id="myform" action="#" method="post"> 
  •                 <legend>PersonalInformation</legend> 
  •                 <input type="text" name="email_address" value="EmailAddress"/> 
  •                 <input type="checkbox" name="checking" value=""/> 
  •             </form> 
  •             <p>Message</p> 
  •         </div><!--Endmain--> 
  •     </div><!--Endwrapper--> 
  •     <div id="footer"> 
  •         <p>Footermessage</p> 
  •     </div><!--Endfooter--> 
  • </body> 
  • </html>
  •   以上示例代码的树形图如下:

      很简单,是不是?从现在开始我们可以将html或xhtml看做一棵树,不过我们想做的是程序员,这些植物学的理论有什么用处?答案就在下一个要点之中。

    42/4<1234>
    《2023软件测试行业现状调查报告》独家发布~

    关注51Testing

    联系我们

    快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

    法律顾问:上海兰迪律师事务所 项棋律师
    版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
    投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

    沪ICP备05003035号

    沪公网安备 31010102002173号