1.Jquery 中言秸, $(document).ready()是什么意思软能?和window.onload 的區(qū)別? 還有其他什么寫法或者替代方法举畸?
window.onload 是要等待到整個(gè)網(wǎng)頁都加載好了再執(zhí)行JS
$(document).ready()則是等待到整個(gè)網(wǎng)頁的DOM節(jié)點(diǎn)加載好后就執(zhí)行JS,不需要等待圖片等加載凳枝。
2.$node.html()和$node.text()的區(qū)別?
$node.html():是輸出$node的整個(gè)html結(jié)構(gòu)包括里面的內(nèi)容
$node.text():僅輸出節(jié)點(diǎn)的內(nèi)容抄沮,不輸出結(jié)構(gòu)
3.$.extend 的作用和用法?
將兩個(gè)或更多對(duì)象的內(nèi)容合并到第一個(gè)對(duì)象跋核。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.extend demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var object1 = {
apple: 0,
banana: { weight: 52, price: 100 },
cherry: 97
};
var object2 = {
banana: { price: 200 },
durian: 100
};
// Merge object2 into object1
$.extend( object1, object2 );
// Assuming JSON.stringify - not available in IE<8
$( "#log" ).append( JSON.stringify( object1 ) );//{"apple":0,"banana":{"price":200},"cherry":97,"durian":100}
// Merge object2 into object1, recursively
$.extend( true, object1, object2 );
// Assuming JSON.stringify - not available in IE<8
$( "#log" ).append( JSON.stringify( object1 ) );//{"apple":0,"banana":{"weight":52,"price":200},"cherry":97,"durian":100}
</script>
</body>
</html>
4.JQuery 的鏈?zhǔn)秸{(diào)用是什么?
當(dāng)jQuery的方法的返回值仍為當(dāng)前對(duì)象時(shí)可以繼續(xù)調(diào)用該對(duì)象的方法就叫做鏈?zhǔn)秸{(diào)用叛买。
$(ele).parents().find().addClass().hide();
5.JQuery ajax 中緩存怎樣控制?
cache (默認(rèn): true, dataType為"script"和"jsonp"時(shí)默認(rèn)為false)
類型: [Boolean]
如果設(shè)置為 false 砂代,瀏覽器將不緩存此頁面。注意: 設(shè)置cache
為 false將在 HEAD和GET請(qǐng)求中正常工作率挣。它的工作原理是在GET請(qǐng)求參數(shù)中附加"_={timestamp}"(時(shí)間戳)刻伊。該參數(shù)不是其他請(qǐng)求所必須的,除了在IE8中椒功,當(dāng)一個(gè)POST請(qǐng)求一個(gè)已經(jīng)用GET請(qǐng)求過的URL捶箱。
6.jquery 中 data 函數(shù)的作用
.data()方法允許我們?cè)贒OM元素上綁定任意類型的數(shù)據(jù),避免了循環(huán)引用的內(nèi)存泄漏風(fēng)險(xiǎn)。
我們可以在一個(gè)元素上設(shè)置不同的值动漾,之后獲取這些值:
$("body").data("foo", 52);
$("body").data("bar", { myType: "test", count: 40 });
$("body").data({ baz: [ 1, 2, 3 ] });
$("body").data("foo"); // 52
$("body").data(); // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2, 3 ] }