zoukankan      html  css  js  c++  java
  • 常用js代码集

    验证码

    <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, '
    $1
    ');
        reg = /([[]])/g;
        json = json.replace(reg, '
    $1
    ');
        reg = /(\,)/g;
        json = json.replace(reg, '$1
    ');
        reg = /(
    
    )/g;
        json = json.replace(reg, '
    ');
        reg = /
    \,/g;
        json = json.replace(reg, ',');
        if (!options.newlineAfterColonIfBeforeBraceOrBracket) {        
            reg = /:
    {/g;
            json = json.replace(reg, ':{');
            reg = /:
    [/g;
            json = json.replace(reg, ':[');
        }
        if (options.spaceAfterColon) {         
            reg = /:/g;
            json = json.replace(reg, ': ');
        }
        $.each(json.split('
    '), 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 + '
    ';
            pad += indent;
        });
        return formatted;
    };
    

      

  • 相关阅读:
    Python简介
    名词术语 1
    TypeError: 'method' object is not subscriptable 一般是函数没加括号导致的
    MYSQL 使用命令行导入文本数据 csv数据
    日期函数格式化
    日期函数——第几天、第几周、星期几、第几季度
    日期函数——MYSQL
    集合常见面试题
    输入一个随机整数,输出对应的大写
    Oracle数据库基本sql语句
  • 原文地址:https://www.cnblogs.com/xielisen/p/5454008.html
Copyright © 2011-2022 走看看