时间:2021-07-01 10:21:17 帮助过:4人阅读
输出结果为:
<!DOCTYPE html>
<html>
<head>
<scriptsrc="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<divid="log"></div>
<script>
var defaults ={validate:false,limit:5,name:"foo"};
var options ={validate:true,name:"bar"};
/* merge defaults and options, without modifying defaults */
var settings =$.extend({},defaults,options); // 在插件开发中经常会用到
varprintObj =typeofJSON !="undefined"?JSON.stringify :function(obj){
vararr =[];
$.each(obj,function(key,val){
varnext =key +": ";
next +=$.isPlainObject(val)?printObj(val):val;
arr.push(next );
});
return"{ "+ arr.join(", ")+" }";
};
$("#log").append("<div><b>defaults -- </b>"+printObj(defaults)+"</div>");
$("#log").append("<div><b>options -- </b>"+printObj(options)+"</div>");
$("#log").append("<div><b>settings -- </b>"+printObj(settings)+"</div>");
</script>
</body>
</html>