jQuery练习(鼠标移来移去,焦点获得失去)

 练习链式操作等
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4.     <title>jQuery鼠标移来移去,焦点获得失去</title>
  5. <script type="text/ecmascript" src="../js/jquery-1.2.6.js"></script>
  6. <script type="text/ecmascript">
  7.     //添加获得焦点失去焦点
  8.     $("document").ready(function(){
  9.         $("input[@type='text'],input[@type='password'],textarea").focus(function(){
  10.             $(this).css({background:"#fcc", border:"1px solid #f00"}).blur(function(){
  11.                 $(this).css({background:"transparent", border: "1px solid #ccc"})
  12.             })
  13.         });
  14.     });
  15.     //根据标签名找标签,$(input[@type='password'])多个标签之间用逗号隔开.
  16.     //$("..").focus(function(){$(this).})//链式操作用$(this)取得当前对象.
  17.     //设置css的方法:$(this).css({这里添写键值对});//形式key:"value"
  18.     //$().hover(f1(){},f2(){})//hover的用法
  19.     $(function(){
  20.         $("input[@type='text'],input[@type='password'],textarea").hover(function(){
  21.             $(this).css({background:"#369", border:"1px solid #369"})},function(){
  22.                 $(this).css({background:"#f6f", border:"1px solid #f6f"})
  23.             }
  24.         )
  25.     });
  26.     //去掉这个会有小毛病
  27.     $(document).ready(function(){
  28.         if ($.browser.msie){
  29.           $("input[@type='text'], input[@type='password'], textarea").focus(function(){
  30.                 $(this).addClass("focus")
  31.             }).blur(function(){
  32.                     $(this).removeClass("focus")
  33.                 });
  34.         }
  35.     })
  36.     //两种链式操作方法
  37.     $(function(){
  38.         //第一种,像穿珠子,比较清晰,我比较喜欢。
  39.         //$("#d1").mouseover().mouseout()
  40.         $("#d1").mouseover(function(){
  41.             $(this).html("over");
  42.         }).mouseout(function(){
  43.             $(this).html("out");
  44.         })
  45.         //第二种,一层套一层,不大习惯。像C#语法,但又不能像那样格式。
  46.         //$("#d2").mousedown(function(){
  47.         //  $(this).css().mouseup(function(){
  48.         //      $(this).css()
  49.         //  })
  50.         //});
  51.         $("#d2").mousedown(function(){
  52.             $(this).html("down").mouseup(function(){
  53.                 $(this).html("up")
  54.             })
  55.         });
  56.     });
  57. </script>
  58. </head>
  59. <body>
  60. <div>
  61. <input type="text" id="i1" />
  62. <textarea id="TextArea1" cols="20" rows="2"></textarea>
  63. <div id="d1">hello</div>
  64. <div id="d2">hi,hi</div>
  65. </div>
  66. </body>
  67. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值