If there are too many values for mutual value transfer between the front and backend, writing will be cumbersome, tiring, and error-prone. Here is a set of ways to use mark tag attributes to pass values. The backend value acquisition and frontend binding have been greatly simplified.
$.extend({
//Convert json object into string [It seems that jquery does not have this method]
toJSONString: function (object) {
if (object == null)
return;
var type = typeof object;
If ('object' == type) {
If (Array == object.constructor) type = 'array';
else if (RegExp == object.constructor) type = 'regexp';
else type = 'object';
}
switch (type) {
case 'undefined':
case 'unknown':
return;
break;
case 'function':
case 'boolean':
case 'regexp':
return object.toString();
break;
case 'number':
Return isFinite(object) ? object.toString() : 'null';
break;
case 'string':
return '"' object.replace(/(
\|")/g, "
\$1").replace(/n|r|t/g, function () {
var a = arguments[0];
return (a == 'n') ? '\n' : (a == 'r') ? '\r' : (a == 't') ? '\t' : ""
'"';
break;
case 'object':
If (object === null) return 'null';
var results = [];
for (var property in object) {
var value = $.toJSONString(object[property]);
if (value !== undefined) results.push($.toJSONString(property) ':' value);
}
return '{' results.join(',') '}';
break;
case 'array':
var results = [];
for (var i = 0; i < object.length; i ) {
var value = $.toJSONString(object[i]);
if (value !== undefined) results.push(value);
}
return '[' results.join(',') ']';
break;
}
}
});