标签:io for ar cti amp new size ad
//第一参数是:Json对象,第二个是 序号 第三个 页数 第四 当前页数
String.prototype.format = function (args, sid, pagesize, currentpage) {
if (arguments.length > 0) {
var result = this;
if (arguments.length == 1 && typeof (args) == "object") {
for (var key in args) {
var reg = new RegExp("({" + key + "})", "g");
result = result.replace(reg, args[key]);
}
}
else if (arguments.length == 4 && typeof (args) == "object") {
sid = pagesize * (currentpage - 1) + sid;
result = result.replace(‘{sid}‘, sid);
for (var key in args) {
var reg = new RegExp("({" + key + "})", "g");
result = result.replace(reg, args[key]);
}
}
else {
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] == undefined) {
return "";
}
else {
var reg = new RegExp("({[" + i + "]})", "g");
result = result.replace(reg, arguments[i]);
}
}
}
return result;
}
else {
return this;
}
}
把以上脚本追加到jquery.js最后.
<script>
$(document).ready(function () {
var a1 = ‘<tr citycode="{CantCode}">顶戴\sfsd[{sid}]‘;
var b = a1.format(eval("("+"{‘CantCode‘:‘0000‘}"+")"), 1, 10, 2);
alert(b);
});
</sctipt>
发现a1的{CantCode}被替换为Json的CantCode属性的值0000了.{sid}就是分页序号也可以自己改上面的Js.
自制 JS.format带分页索引,布布扣,bubuko.com
标签:io for ar cti amp new size ad
原文地址:http://www.cnblogs.com/GoogleGetZ/p/JSformat.html