标签:
一. 获取Url中searchParams
getQueryParamsMap: function(searchUrlWithoutQuestionMark) { var result = {}; var array = searchUrlWithoutQuestionMark.split(‘&‘); for (var i in array) { var keyValue = array[i]; if (!keyValue || keyValue.length == 0) { continue; } var keyValueArray = keyValue.split(‘=‘); if (keyValueArray.length != 2) { continue; } var key = decodeURI(keyValueArray[0]); var value = decodeURI(keyValueArray[1]); result[key] = value; } return result; },
二. 从cookie获取数据
getValueFromCookie: function(name) { var value = "; " + document.cookie; var parts = value.split("; " + name + "="); if (parts.length == 2) { return parts.pop().split(";").shift(); } else { return undefined } },
三. 在cookie中存值
document.cookie = "hasAuthorization=1;path=/;expires=" + expiresDate.toGMTString();
四. 根据正负数设字体颜色
getFontColor: function(value, defaultNullFontColor) { if (!value || isNaN(value) || value === ‘0‘) { return defaultNullFontColor ? defaultNullFontColor : ‘font-color-grey‘; } return value > 0 ? ‘font-color-orange‘ : ‘font-color-green‘; },
五. 把服务端返回的数字处理成显示的值
setDisplayValue: function(value, opts) { var defaultValue = (opts && opts[‘defaultValue‘]) ? opts[‘defaultValue‘] : ‘- -‘; if (!value || isNaN(value) || value === ‘0‘) { if (opts && opts[‘defaultValueForZero‘] && (value === ‘0‘ || value === 0)) { return opts[‘defaultValueForZero‘]; } return defaultValue; } if (opts && $.type(opts[‘specialDict‘]) == ‘object‘) { var specialValue = opts[‘specialDict‘][value]; if (specialValue) { return specialValue; } } if (opts && $.type(opts[‘handleValue‘]) == ‘function‘) { var displayValue = opts[‘handleValue‘](value); } else { var displayValue = value; } if (displayValue > 0) { if (opts && opts[‘noPositive‘]) { return defaultValue; } var addFrontSymbolValue = (opts && opts[‘addFrontSymbolForPositive‘]) ? (opts[‘addFrontSymbolForPositive‘] + displayValue) : displayValue; if (opts && opts[‘addBehindSymbolForPositive‘]) { return (addFrontSymbolValue + opts[‘addBehindSymbolForPositive‘]); } else if (opts && opts[‘addBehindSymbol‘]) { return (addFrontSymbolValue + opts[‘addBehindSymbol‘]); } return addFrontSymbolValue; } else { if (opts && opts[‘noNegative‘]) { return defaultValue; } var addFrontSymbolValue = (opts && opts[‘addFrontSymbolForNegative‘]) ? (opts[‘addFrontSymbolForNegative‘] + displayValue) : displayValue; if (opts && opts[‘addBehindSymbolForNegative‘]) { return (addFrontSymbolValue + opts[‘addBehindSymbolForNegative‘]); } else if (opts && opts[‘addBehindSymbol‘]) { return (addFrontSymbolValue + opts[‘addBehindSymbol‘]); } return addFrontSymbolValue; } }
标签:
原文地址:http://www.cnblogs.com/ccblogs/p/5258772.html