關(guān)注jQuery模擬的這一段代碼即可:
$("#test1").click(function(){
var item = $('.item-1');
alert(item.parent()[0]);//ul .level-3
alert( item.parents().length);//length=7,共7個(gè)
alert( item.parentsUntil('body').length);//length=5,在body前(*不包括body)共5個(gè)parent元素
})
其他的是說(shuō)在純js中實(shí)現(xiàn)上面方法的過(guò)程。通過(guò)對(duì)比,最直觀(guān)的,能發(fā)現(xiàn)JQ給我們節(jié)省的代碼量可不是一點(diǎn)半點(diǎn)
$("#test1").click(function(){
var item = $('.item-1');
alert(item.parent()[0]);//ul .level-3
alert( item.parents().length);//length=7,共7個(gè)
alert( item.parentsUntil('body').length);//length=5,在body前(*不包括body)共5個(gè)parent元素
})
其他的是說(shuō)在純js中實(shí)現(xiàn)上面方法的過(guò)程。通過(guò)對(duì)比,最直觀(guān)的,能發(fā)現(xiàn)JQ給我們節(jié)省的代碼量可不是一點(diǎn)半點(diǎn)
console.log($('.level-2').find('.item-1'));
console.log($('.level-2').children('.item-1'));
console.log($('.level-2').children('.item-1'));
http://jquery.cuishifeng.cn/parent.html看不明白的可以查這個(gè)jQuery API
2016-01-16
document.querySelectorAll() 是 HTML5中引入的新方法,它的使用方式與jQuery的選擇器相同。
例如:
document.querySelectorAll("div");
document.querySelectorAll(".comment");
document.querySelectorAll("#userid");
由于它是HTML5原生的方法,所以不需要添加jQuery引用。
例如:
document.querySelectorAll("div");
document.querySelectorAll(".comment");
document.querySelectorAll("#userid");
由于它是HTML5原生的方法,所以不需要添加jQuery引用。
2016-01-08
其實(shí)我想知道,平時(shí)大家用文檔碎片么?我好像一次都沒(méi)有創(chuàng)建過(guò)文檔碎片。
2016-01-07
很喜歡 看源碼啊 ,雖然很多時(shí)候看不懂,雖然有時(shí)候看的很煩, 但是 看懂的地方,就覺(jué)得 寫(xiě)的很精辟啊