JQuery leaning note1

本文介绍了使用jQuery进行元素操作及动画效果的方法,包括显示隐藏、改变样式、添加删除元素等,并展示了如何通过jQuery选择器定位元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. $(function() {
  2.             $('a').click(function() {
  3.         // the methods of hiding or showing an element
  4.         // in this section, you can try the following methods and see what happens
  5.         // notice that the different type of parameters.
  6.                 $('#box').fadeOut();
  7.         $('#box').fadeOut(3000);
  8.         $('#box').fadeOut('slow);
  9.         $('#box').slideUp('slow');
  10.         $('#box').slideUp(3000);
  11.         $('#box').hide(3000);
  12.         $('#box').fadeIn('slow');
  13.         $('#box').slideDown('slow');
  14.         // here, you can change the element's css class properties
  15.         $('p a').css('color''blue');
  16.             });
  17.         });
  18. $(function() {
  19.             $('#box').click(function() {
  20.         // Use the animate function to animate an element
  21.         // you can change different properties splitted by comma
  22.                 $(this).animate({
  23.                     "left":"300px",
  24.                     "top":"300px",
  25.                     "width":"100px"
  26.                 })
  27.             })
  28.         });
  29. $(function() {
  30.         // notice the different selectors
  31.             $('ul li').css('color''red');
  32.         $('ul li').addClass('alert');
  33.         // select first
  34.         $('ul li:first').addClass('alert');
  35.             // select last
  36.         $('ul li:last').addClass('alert');
  37.         // select even items
  38.         $('ul li:even').addClass('alert');
  39.             // select odd items
  40.         $('ul li:odd').addClass('alert');
  41.         //this starts from the first child
  42.         $('ul li:nth-child(6)').addClass('alert');
  43.         // this is start from 0
  44.         $('ul li:eq(5)').addClass('alert');
  45.         // select items with XPATH
  46.         $('ul li a[title=title]').addClass('alert');
  47.         // select all the anchors under li as its children.
  48.         $('ul li>a').addClass('alert');
  49.         });
  50. $(function() {
  51.             var i = $('li').size();
  52.         // add an item to ul
  53.             $('a#add').click(function() {
  54.                 $('<li>' + ++i + '</li>').appendTo('ul');
  55.             }
  56.             );
  57.             // remove the last item.
  58.             $('a#remove').click(function() {
  59.                 $('li:last').remove();
  60.             });
  61.         });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值