共享一个简单的 Javacript Helper library
生活随笔
收集整理的這篇文章主要介紹了
共享一个简单的 Javacript Helper library
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
直接貼代碼了:
共享一個簡單的 Javacript Helper library,以后會更新!
// JavaScript Document // js配置 | url | 封裝方法等等 // 需要 jQuery 庫 // // // var cookie_prefix = 'cnblogs2012_'; var helperConfig= {DOMAIN: '.tom.com',setCookie: function(name ,val ,extime , domain){var exdate = new Date();var extime = extime ? extime : 12 * 30 * 24 * 60 * 60 * 1000;exdate.setTime(exdate.getTime() + extime);name = cookie_prefix + name;var domain = domain ? domain : this.DOMAIN;document.cookie = name + "=" + val + ";expires=" + exdate.toGMTString()+";domain="+domain+";path=/";},getCookieVal: function(offset){var endstr = document.cookie.indexOf (";", offset);if (endstr == -1)endstr = document.cookie.length;return unescape(document.cookie.substring(offset, endstr));},getCookie: function(name){var arg = cookie_prefix + name + "=";var alen = arg.length;var clen = document.cookie.length;var i = 0;while (i < clen){var j = i + alen;if (document.cookie.substring(i, j) == arg)return this.getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;if (i == 0) break;}return null;},delCookie: function(name,domain){var domain = domain ? domain : this.DOMAIN;this.setCookie(name ,'' ,-1 , domain); // var exdate = new Date(); // exdate.setTime (exdate.getTime() - 10000); // alert(name + "=''; expires="+ exdate.toGMTString()+";domain="+domain+";path=/"); // document.cookie = name + "=''; expires="+ exdate.toGMTString()+";path=/"; },htmldecode:function(input){var converter = document.createElement("DIV");converter.innerHTML = input;var output = converter.innerHTML;converter = null;return output.toString();},//獲得瀏覽器類型getBrower:function(){if(navigator.userAgent.indexOf("MSIE")>0){return"MSIE"}if(navigator.userAgent.indexOf("Firefox")>0){return"Firefox"}if(navigator.userAgent.indexOf("Safari")>0){return"Safari"}if(navigator.userAgent.indexOf("Camino")>0){return"Camino"}if(navigator.userAgent.indexOf("Gecko/")>0){return"Gecko"}} }?
另一個:
var helper2 = {htmlEncode: function(j) {if (!j) return '';j = typeof j != 'string' ? j.toString() : j;j = j.replace(/&/g, '&');j = j.replace(/</g, '<');j = j.replace(/>/g, '>');return j;},setCookie: function(j, k, l) {document.cookie = j + '=' + k + (!l ? '; expires=Thu, 6 Oct 2016 01:00:00 UTC; path=/' : '');},getCookie: function(j) {var k = document.cookie.match(new RegExp('(^|\\s|;)' + j + '=([^;]*)'));return k && k.length > 0 ? k[2] : '';},htmlEncode: function(j) {var k = function(o) {var p = new h.element('span');p.setText(o);return p.getHtml();},l = k('\n').toLowerCase() == '<br>' ?function(o) {return k(o).replace(/<br>/gi, '\n');} : k, m = k('>') == '>' ?function(o) {return l(o).replace(/>/g, '>');} : l, n = k(' ') == ' ' ?function(o) {return m(o).replace(/ /g, ' ');} : m;this.htmlEncode = n;return this.htmlEncode(j);}};?
?
謝謝瀏覽!
轉(zhuǎn)載于:https://www.cnblogs.com/Music/archive/2012/06/12/a-simple-javascript-helper-library.html
總結(jié)
以上是生活随笔為你收集整理的共享一个简单的 Javacript Helper library的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一到关于js函数的前端面试题引发的血案
- 下一篇: 视差图获取