zoukankan      html  css  js  c++  java
  • jQuery截取字符串、日期字符串转Date、获取html中的纯文本

    jQuery截取字符串、日期字符串转Date、获取html中的纯文本。

    var com = com || {};
    (function ($, com) {
        /*
        * 截取字符串
        * @param str:要截取的字符串
        * @param len:保留多少字符
        * @param symbol:超过之后字符串末端要添加的字符
        */
        com.cutStr = function (str, len, symbol) {
            if (symbol == undefined) {
                symbol = "...";
            }
            len = len || 25;
            var result = str;
            if (str) {
                if (str.length && str.length > len)
                    result = str.substr(0, len) + symbol;
            }
            return result;
        },
        /*
        * 将日期字符串转化为Date
        * (如:将"2016-12-24 20:13:14"转化为Date格式)
        * @param d:待转化字符串(传入的时间不能有毫秒)
        */
        com.getDate = function (d) {
            //部分浏览器(IE)不支持日期格式“yyyy-MM-dd hh:mm:ss”,必须将“-”转化为“/”
            var date = new Date(Date.parse(d.replace(/-/g, "/")));
            return date;
        },
        /*
        * 获取html代码的纯文本
        * @param html
        */
        com.removeHTMLTag = function (html) {
            html = html.replace(/</?[^>]*>/g, ''); //去除HTML tag
            html = html.replace(/[ | ]*
    /g, '
    '); //去除行尾空白
            //html = html.replace(/
    [s| | ]*
    /g,'
    '); //去除多余空行
            html = html.replace(/&nbsp;/ig, '');//去掉&nbsp;
            html = html.replace(/s/g, ''); //将空格去掉
            return html;
        }
    })(jQuery, com);
  • 相关阅读:
    嘉佣坊
    HTTPS
    OWIN 为WebAPI
    C#并行编程
    ASP.NET 运行
    DocFX
    oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解
    Facebook新框架React Native,一套搞定App开发[转]
    MVC 中使用 SignalR 实现推送功能
    生产都消费者模式的一个demo,消费者设置缓存
  • 原文地址:https://www.cnblogs.com/wz122889488/p/6273018.html
Copyright © 2011-2022 走看看