jQuery(一)

jQuery

:支持链式编程,DOM/BOM/JavaScript的类库;
:jQuery方法内置循环 : $('#tb:checkbox').xxxx
循环:

$('#tb:checkbox').each(function(k){
					//k当前索引
					//this,DOM,当前循环元素$(this)
				 })

1. 选择器:

  • id : $('#id')
  • class : $('.c1')
  • 标签:$('a')
  • 组合:$('a,.c1')
  • 层级 $('a #id') //子子孙孙 ; $('a>#id') //孩子
  • 基本 :first; :last; :eq(index)
  • 属性 $('[alex]') 具有alex属性的所有标签; $('[alex = "123"]') alex属性等于123的标签
  • input系列 $(":checkbox"); $(":text"); $('input[type="text"]')
  • 下一个 $("prev+next")
    2. 筛选器:
  • $(this).next() //下一个
  • $(this).nextAll()
  • $(this).nextUntil()
  • $(this).prev()
  • $(this).prevAll()
  • $(this).prevUntil()
  • $(this).parent()
  • $(this).parents()
  • $(this).parentUntil('#i1')
  • $(this).children()
  • $(this).siblings() //兄弟标签不包含自己
  • $(this).find('.content') //子子孙孙查找
  • $('li:eq(1)')
  • $('li').eq(1)
  • first()
  • last()
  • hasClass(class)
    3. 样式操作:
  • $('.i1').addClass('hide')
  • $('#i1').removeClass('hide')
  • $('#i1').toggleClass('hide') //有则取没有则加
  • hasClass();
    4. 属性操作:
  • 专门用于做自定义属性
$(..).attr('n')
$(..).attr('n''v')
$(..).removeAttr('n')
  • 专门用于chekbox,radio
$(..).prop('checked')
$(..).prop('checked',true)

5. 绑定事件:

$(..).click(function(){});

6. 文本操作:

  • $('').text() 获取文本
  • $('').text(‘a’) 设置文本
  • $('').html()
  • $('').html(‘<a>1</a>’)
  • $('').val() input系列获取
  • $('').val('dsa') input系列设置
  • 7. 文档处理:
  • append('..') //内部追加
  • prepend('..') //内部头添加
  • after('..') //前一个元素
  • brfore('..') //后一个元素
  • remove()
  • empty()
  • clone()
    PS: $('').index() 获取索引位置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值