JQuery模板插件 jquery.tmpl 动态ajax扩展

2020-05-23 06:16:20易采站长站整理

$.Tmpl_Data(te, data, fun, template.cache);
return;
}
$.ajax({
type: “GET”,
data: template.data,
url: template.url,
dataType: “html”,
cache: false,
context: { template: template, data: data },
error: function(e) {
throw “get template error(” + this.template.url + “?” + this.template.data + “):” + e;
},
success: function(tmpltemplate) {
var te = $(‘<script type=”text/x-jquery-tmpl”>’ + tmpltemplate + ‘</script>’).appendTo(document.body);
te.attr(“url”, (this.template.url + “?” + this.template.data));
$.Tmpl_Data(te, this.data, fun, this.template.cache);
}
});
}
});
})(jQuery);

测试代码:
前台:

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Tmpl3.aspx.cs” Inherits=”Tmpl3″ %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22>
<html xmlns=”http://www.w3.org/1999/xhtml%22>
<head runat=”server”>
<title></title>
<script src=”Script/jquery-1.6.4.js” type=”text/javascript”></script>
<script src=”Script/jquery-jquery-tmpl-07d08cb/jquery.tmpl.js” type=”text/javascript”></script>
<script type=”text/javascript” src=”Script/Remote-Tmpl.js”></script>
<script type=”text/javascript”>
; String.format = function() {
var s = arguments[0];
for (var i = 0; i < arguments.length – 1; i++) {
var reg = new RegExp(“{” + i + “}”, “gm”);
s = s.replace(reg, arguments[i + 1]);
}
return s;
};
function AjaxDeleteInvoke(id) {
alert(String.format(“AjaxDeleteInvoke:id={0}”, id));
}
$(function() {
$.Tmpl({ url: “TmplTemplate.htm”, data: “test=1” }, { url: “Tmpl3.aspx”, data: “ajax=1” }, function(t, te, da) {
t.appendTo(“#test>tbody”);
$(“#test>tbody table”).hide();
$(“#test .detailsImg”).live(“click”, function() {
var state = $(this).data(“state”);
var $tr = $(this).parent().parent();
if (state == “o”) {
$(“table”, $tr.next()).hide();
$(this).data(“state”, “c”);
$(this).attr(“src”, “Image/folder_o.png”);
} else {
$(“table”, $tr.next()).show();
$(this).data(“state”, “o”);
$(this).attr(“src”, “Image/folder_c.png”);
}
});
});
// $(“#btntest”).bind(“click”, function() {
// $.Tmpl({ url: “TmplTemplate.htm”, data: “test=1” }, { url: “Tmpl3.aspx”, data: “ajax=1” }, function(t, te, da) {