欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

//閉包限定命名空間
(function ($) {
 $.fn.extend({
 "ajaxrefresh": function (options) {
 //檢測用戶傳進來的參數(shù)是否合法
 if (!isValid(options))
 return this;
 var opts = $.extend({}, defaluts, options); //使用jQuery.extend 覆蓋插件默認參數(shù)
 var $this = $(this); //獲取當前dom 的 jQuery對象
 $.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));
 }
 });
 }
 });
 
 }
 });
 //默認參數(shù)
 var defaluts = {
 template: '',
 url:''
 };
 //私有方法,檢測參數(shù)是否合法
 function isValid(options) {
 return !options || (options && typeof options === "object") ? true : false;
 }
})(window.jQuery);

調用方法:

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

預覽效果:

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

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關文章

最新評論