[jQuery]DOM总结

来源:互联网 发布:lte测试软件 编辑:程序博客网 时间:2024/06/08 11:36

1、DOM

// TODO DOM介绍

2、DOM选择

2.1$()函数

$()函数将DOM元素包装在jQuery对象中。
$()接受CSS选择符返回对应元素的jQuery对象。
防止名称冲突,使用jQuery.noConflict()

<script>    jQuery.noConflict();    jQuery(document).ready(function){        // jQuery code    });</script>

// TODO CSS选择器页面
选择器参考手册

2.2CSS选择符

基本选择符:标签名,ID,类。
$(‘#exampleID > li:not(.ExampleClass)’):选择id为exampleID下一级的所有class不为ExampleClass的li元素

2.3属性选择器

$(‘a[href^=”mailto:”]’):选择带有href属性且以mail开头的a元素

2.4自定义选择符

2.5DOM遍历方法

使用filter隐式遍历
筛选外链

$('a').filter(function(){    return this.hostname && this.hostname != location.hostname;});

2.6连缀

几乎所有jQuery方法返回一个jQuery对象
可以通过一行代码取得多个元素集合并执行多次操作
// TODO 连缀

3DOM操作

3.1类操作

.addClass() .removerClass()

3.2非类属性

修改title为text内容,id为第几项

$('a').attr({    title:function(){        return $(this).text();    },    id:function(index, OldValue){        return index;    }});

3.3DOM树操作

添加
删除
clone

0 0
原创粉丝点击