您的位置:首页 > Web前端 > JQuery

复习jquery 笔记 版本1.2.1,jquery in action 总结细节

2017-05-31 10:35 603 查看
不编号,随手记。

$(function(){});

chapter2 包装集 wrapper

$(“xxx”)得到的是包装集, 类似数组但没有数组方法,.size()等于数组的length,可用.get()转为数组。要引用其中元素需要用到[0]。也可以用包装集.index(元素)的方法来取得该元素在包装集中的顺序下标。

()里面都要加引号,不能是直接的element tag。

nth-child是以1开始计数的,其余都是以0开始计数的,不管是包装集还是slice还是别的什么方法。

.add( )

.not()和.filter( )类似,都可传入筛选选择器(就是以[或者:开头的,比如not(“[alt]”))

区别在于,.not()还可以传入元素并删除,而filter可以传函数,return this….,并删除return false的包装集元素。

.not也能传函数了。

As of jQuery 1.4, the .not() method can take a function as its argument in the same way that .filter() does. Elements for which the function returns true are excluded from the filtered set; all other elements are included.

.contains()已经被移除,用:contains选择器来find text 与之match的元素

以下方法不改变原始包装集:

.slice(start, end)

且,以下接受选择器expression, 而且是任意的选择器expression

.children() 直接子元素,不是后代

.contents()

Get the children of each element in the set of matched elements, including text and comment nodes.

.parents()& .parent()

.prev()&.prevAll() 需要是兄弟元素

.siblings()

.find()找的是子元素

.end()回退上一个包装集

.andSelf()合并当前与上一个包装集

chapter3 特性与属性

没讲清楚,我的理解是html tag里的是特性,而解释为dom元素后为属性。

.each(function(index){this.alt=”….”})

函数,参数为包装集元素下标,当前元素用this来表示。

注意attr里没有className 只有class

attr 和 css 都可以传多个参数来set 但不能传多个参数来get ,以对象的方式{ 键值对,键值对},中间用,隔开。

attr 用来搞自己传的data-xx属性 而css传css, prop传固有和动态属性

appendTo 和 append 当移动的是本身html中的元素时,是直接移动而不是复制过去,无论多少个。这个跟版本有关,3.x的版本是移动。1.x跟目标元素(被append 的锚元素)的数量有关。

append/prepend (To),目标元素与动的元素都是父子关系;

before,after、insertBefore/After 都是兄弟关系。

注意大小写。

var command = $('input[name=command]:checked').val();
var insertcmd = 'insert' + command[0].toUpperCase() + command.slice(1)


可以用’xx-xx’也可以用camel写属性

只有add方法,没有jquery(”,”)的方法来同时选中两个符合标准的操作集

$(‘a’,’b’)其实是在’b’中find’a’ 包装集是包装集 是不同的 元素是一样的

var hh= ($('section').find('input')[0]===$('input','section'))[0] //true
var ff= ($('section').find('input')===$('input','section'))//false
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息