常用js代码集
2024-08-25 01:44:45
验证码
<img src="<{:url('publics/verify','id=login')}>" onclick="this.src='{:url('publics/verify','id=login')}'">
json格式化显示
/**
* 格式化显示json格式数据
*/
function formatJson(json, options) {
var reg = null,
formatted = '',
pad = 0,
PADDING = ' ';
options = options || {};
options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
if (typeof json !== 'string') {
json = JSON.stringify(json);
} else {
json = JSON.parse(json);
json = JSON.stringify(json);
}
reg = /([\{\}])/g;
json = json.replace(reg, '\r\n$1\r\n');
reg = /([\[\]])/g;
json = json.replace(reg, '\r\n$1\r\n');
reg = /(\,)/g;
json = json.replace(reg, '$1\r\n');
reg = /(\r\n\r\n)/g;
json = json.replace(reg, '\r\n');
reg = /\r\n\,/g;
json = json.replace(reg, ',');
if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
reg = /\:\r\n\{/g;
json = json.replace(reg, ':{');
reg = /\:\r\n\[/g;
json = json.replace(reg, ':[');
}
if (options.spaceAfterColon) {
reg = /\:/g;
json = json.replace(reg, ': ');
}
$.each(json.split('\r\n'), function(index, node) {
var i = 0,
indent = 0,
padding = '';
if (node.match(/\{$/) || node.match(/\[$/)) {
indent = 1;
} else if (node.match(/\}/) || node.match(/\]/)) {
if (pad !== 0) {
pad -= 1;
}
} else {
indent = 0;
}
for (i = 0; i < pad; i++) {
padding += PADDING;
}
formatted += padding + node + '\r\n';
pad += indent;
});
return formatted;
};
最新文章
- Java多线程基础知识篇
- SQL Server 2008数据库日志收缩
- Android IOS WebRTC 音视频开发总结(八十一)-- WebRTC靠谱吗?有没有适合的SDK推荐?
- [Spring MVC] - @ModelAttribute使用
- js实现右侧的分享效果
- 简单修改 MySQL 的 root 账号密码
- unix network programming(3rd)Vol.1 [第1章]《读书笔记系列》
- Render Texture的使用(截取rendertexture的一帧到Texture2D)
- win2003+IIS6+PHP5.3.8+MSSQL2008的安装配置
- 【转】CTS tests 4.2_r4
- gamma
- eclipse代码提示配置
- linux shell 找端口号及对应的进程
- Js之on与addEventListener的使用与两者的不同
- require.js模块化写法
- python时间模块time
- PL-SLAM
- java运行报错:nested exception is java.lang.NoSuchFieldError: INSTANCE,但使用@Test测试是好的
- 【ORACLE】oracle数据库用户密码复杂度配置
- 用EXCEL的VBA将PHPCMS的备份文件转换成HTML的一次尝试