源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jquery自定义插件结合baiduTemplate.js实现异步刷新(附源码)

  • 时间:2020-08-10 23:12 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jquery自定义插件结合baiduTemplate.js实现异步刷新(附源码)
上一篇记录了[url=http://www.1sucai.cn/article/100901.htm]BaiduTemplate模板引擎使用示例(附源码)[/url],在此基础上对使用方法进行了封装 [b]自定义插件jajaxrefresh.js 代码如下:[/b]
//闭包限定命名空间
(function ($) {
 $.fn.extend({
 "ajaxrefresh": function (options) {
 //检测用户传进来的参数是否合法
 if (!isValid(options))
 return this;
 var opts = $.extend({}, defaluts, options); //使用jQuery.extend 覆盖插件默认参数
 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));
 }
 });
 }
 });
 
 }
 });
 //默认参数
 var defaluts = {
 template: '',
 url:''
 };
 //私有方法,检测参数是否合法
 function isValid(options) {
 return !options || (options && typeof options === "object") ? true : false;
 }
})(window.jQuery);
[b]调用方法:[/b]
$(document).ready(function () {
 $("#list").ajaxrefresh({ template: 'templates/list.html', url: 'data/data.txt' });
 });
[b]预览效果:[/b] [img]http://files.jb51.net/file_images/article/201612/2016122216170621.jpg[/img] [b][url=http://xiazai.jb51.net/201612/yuanma/baiduTemplate-v1.1_jb51.rar]源码下载[/url]:[url=http://xiazai.jb51.net/201612/yuanma/baiduTemplate-v1.1_jb51.rar]http://xiazai.jb51.net/201612/yuanma/baiduTemplate-v1.1_jb51.rar[/url][/b] 以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持编程素材网!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部