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(/[ | ]*\n/g, '\n'); //去除行尾空白
//html = html.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
html = html.replace(/&nbsp;/ig, '');//去掉&nbsp;
html = html.replace(/\s/g, ''); //将空格去掉
return html;
}
})(jQuery, com);

jQuery截取字符串、日期字符串转Date、获取html中的纯文本的更多相关文章

  1. jquery截取、判断字符串的长度,中英文都可

    计算字符串的长度(一个双字节字符长度计2,ASCII字符计1) String.prototype.len=function(){return this.replace([^\x00-\xff]/g,& ...

  2. PHP提取富文本字符串中的纯文本,并进行进行截取

    this is my first markdown article,i hope you like it /** * 提取富文本字符串的纯文本,并进行截取; * @param $string 需要进行 ...

  3. .net core web api 获取request body的纯文本

    本文代码 https://github.com/wuhaibo/readPlainTextDotNetCoreWepApi 总有些时候我们希望获得Request body 的纯文本 那么怎么做呢?很简 ...

  4. js 字符串日期 转成 Date

    只支持 2015/09/23 反斜杠这样类型 2015-09-23 单横的这种无法识别 var dateStr='${endDate}'; dateStr=dateStr.replace(/-/g,' ...

  5. 获取input type=file 的文件内容(纯文本)

    一.获取input type=file 的文件内容(纯文本) 1.需求一 通过点击其他事件,来触发 文件选择框(限定格式为 .c 文件),而不是手动鼠标点击触发. [思路:] step1:将 inpu ...

  6. jquery获取当前按钮、截取字符串、字符串拼接、动态循环添加元素

    截取字符串:字符串拼接:动态循环添加元素:获取当前按钮: {data : null, render: function(data, type, row ) { var loginName = $(&q ...

  7. 根据日期字符串获取星期几,日期获取星期,时间获取星期,js获取星期

    根据日期字符串获取星期几,日期获取星期,时间获取星期,js获取星期 >>>>>>>>>>>>>>>>&g ...

  8. Java中Date()类 日期转字符串、字符串转日期的问题(已解决)

    Java中Date()类 日期转字符串.字符串转日期的问题 今天在写东西的时候突然发现一个问题,就是先new 一个Date()然后将生成的值转为字符串, 然后再将转换后的字符串再次用new Date( ...

  9. 3.javascript转换日期字符串为Date对象

    js中文网 阮一峰 1.求format“xxxx年xx月xx日 xx:xx”类型的两个日期天数差 var start = "2017年09月17日 13:51"; var end ...

随机推荐

  1. POJ1950----DFS

    Dessert Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6193   Accepted: 2299 Descripti ...

  2. Ubuntu 分辨率更改 xrandr Failed to get size of gamma for output default

    sudo vim /etc/xorg.conf copy: Section "Monitor" Identifier "Monitor0" VendorName ...

  3. Python property() 函数

    Python property() 函数  Python 内置函数 描述 property() 函数的作用是在新式类中返回属性值. 语法 以下是 property() 方法的语法: class pro ...

  4. 72. Edit Distance (String; DP)

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  5. python中的&&及||

    首先说明一下,在python中是没有&&及||这两个运算符的,取而代之的是英文and和or.其他运算符没有变动. 接着重点要说明的是python中的a.any(),我之所以会涉及到这个 ...

  6. iOS - OC - 打印信息 - xcode 中文打印

    #import <Foundation/Foundation.h> @implementation NSDictionary (Log) //重写系统的方法控制输出 -(NSString ...

  7. 不使用if switch 各种大于 小于 判断2个数的大小

    哥们写的代码: dword big; __asm { mov eax,a mov ebx,b cmp eax,ebx jle HOHO big =ebx HOHO: big = eax } 网上搜了一 ...

  8. noi 1997 最优乘车

    H城是一个旅游胜地,每年都有成千上万的人前来观光.为方便游客,巴士公司在各个旅游景点及宾馆,饭店等地都设置了巴士站并开通了一些单程巴上线路.每条单程巴士线路从某个巴士站出发,依次途经若干个巴士站,最终 ...

  9. centos 6.5 安装mysql

    步骤1: yum -y install mysql-server 步骤2: chkconfig mysqld on 步骤3: service mysqld start mysql -u root se ...

  10. android通过 Intent 传递类对象

    Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...