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);
  • 相关阅读:
    判断设备类型是iPhone还是iPad
    robotium使用中的问题
    onTouchEvent()
    [ObjectC]@class的含义
    关于左外连接和内连接的区别
    web services = XML + HTTP
    c#中的变量
    C#捕捉异常
    ASP.NET中Visio图形的控制与数据的动态显示
    用存储过程在数据库中批量插入数据1w条
  • 原文地址:https://www.cnblogs.com/wz122889488/p/6273018.html
Copyright © 2011-2022 走看看