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()获取索引位置
3579

被折叠的 条评论
为什么被折叠?



