亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery自定義插件結(jié)合baiduTemplate.js實(shí)現(xiàn)異步刷新(附源碼)

 更新時(shí)間:2016年12月22日 16:14:05   作者:Chevin  
本文主要介紹了jquery自定義插件結(jié)合baiduTemplate.js實(shí)現(xiàn)異步刷新的具體實(shí)例,具有很好的參考價(jià)值,需要的朋友一起來(lái)看下吧

上一篇記錄了BaiduTemplate模板引擎使用示例(附源碼),在此基礎(chǔ)上對(duì)使用方法進(jìn)行了封裝

自定義插件jajaxrefresh.js 代碼如下:

//閉包限定命名空間
(function ($) {
 $.fn.extend({
 "ajaxrefresh": function (options) {
 //檢測(cè)用戶(hù)傳進(jìn)來(lái)的參數(shù)是否合法
 if (!isValid(options))
 return this;
 var opts = $.extend({}, defaluts, options); //使用jQuery.extend 覆蓋插件默認(rèn)參數(shù)
 var $this = $(this); //獲取當(dāng)前dom 的 jQuery對(duì)象
 $.ajax({
 url: opts.url,
 dataType: "json",
 success: function (data) {
 var template = opts.template;
 $.ajax({
 url: template,
 dataType: "html",
 success: function (val) {
 $this.html(baidu.template(val, data));
 }
 });
 }
 });
 
 }
 });
 //默認(rèn)參數(shù)
 var defaluts = {
 template: '',
 url:''
 };
 //私有方法,檢測(cè)參數(shù)是否合法
 function isValid(options) {
 return !options || (options && typeof options === "object") ? true : false;
 }
})(window.jQuery);

調(diào)用方法:

$(document).ready(function () {
 $("#list").ajaxrefresh({ template: 'templates/list.html', url: 'data/data.txt' });
 });

預(yù)覽效果:

源碼下載http://xiazai.jb51.net/201612/yuanma/baiduTemplate-v1.1_jb51.rar

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論