zoukankan      html  css  js  c++  java
  • js对特殊字符转义、时间格式化、获取URL参数

    /*特殊字符转义*/
    function replace_html(str) {
    var str = str.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, '&quot;');
    return str;
    }
    /*
    *时间格式化
    *例子:time = new Date().Format("yyyy-MM-dd hh:mm:ss");
    */
    Date.prototype.Format = function (result) {
    var o = {
    "M+": this.getMonth() + 1, //month
    "D+": this.getDate(), //day
    "h+": this.getHours(), //hours
    "m+": this.getMinutes(), //minutes
    "s+": this.getSeconds(), //seconds
    "q+": Math.floor((this.getMonth() + 3) / 3), // season
    "S": this.getMilliseconds() //milliseconds
    };
    if (/(Y+)/.test(result)) {
    result = result.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o){
    if (new RegExp("(" + k + ")").test(result)) {
    result = result.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    }
    }
    return result;
    };
    
    
    /*
    *获取URL参数
    */
    function getQueryString(key){
    var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null){
    return unescape(r[2]);
    }
    return null;
    }
  • 相关阅读:
    告别零码软件
    win+mingw+libxml2试用笔记
    beacon with java 1.7 on fedora
    mininet指令详解
    java Socket完美实例
    gnome3 下 qt 应用极其丑陋的解决方案
    org.apache.log4j Class Level
    Mac如何修改文本文件编码
    unity性能优化相关
    平面图判定
  • 原文地址:https://www.cnblogs.com/zzp5980/p/5117386.html
Copyright © 2011-2022 走看看