jQuery

1.jQuery中的html(),text(),val()方法

html()

无参:获取html的值

有参数html:设置html的值

text()

无参:获取文本值 有参数

text:设置文本值

val()

无参:获取value的值

有参数value:设置value的值

2.jQuery中的工具方法

1) get(); //以数组的形式返回DOM节点。 console.log($('div').get());

2) toArray(); //返回一个包含jQuery对象结合中的所有DOM元素数组。 console.log($('div').toArray());

3) eq(index); //返回index位置上的jQuery对象。 console.log($('div').eq(1).get(0));

4) filter(function(index,item){}); //过滤器函数,返回jQuery对象。 var $result = $('div').filter(function(index,item){ return index == 2; });

5) map(function(index,item){}); //用于获取或设置元素集合中的值。 var $result = $('div').map(function(index,item){ return $(item).html() });

6) each(function(index,item){}); //遍历一个jQuery对象。 $('div').each(function(index,item){ console.log(index,'--',item); });

7) slice(0,3); //截取 var $result = $('div').slice(0,3); console.log($result.get()); });

8) not()

9) first()

10) last()

11) is()

12) has()

 

3.jQuery中属性设置函数

 

//获取属性值 attr(key) prop(key)

//删除属性 removeAttr(attributeName) removeProp(propertyName)

//批量设置属性 css(key) /

/添加类 addClass(className)

//判断有没有指定的类,有,返回true,否则返回false hasClass(className)

//删除类 removeClass(className)

posted on 2020-11-19 20:41  季昂  阅读(55)  评论(0编辑  收藏  举报