JS一些常用方法的封裝

過濾html標籤以及nbsp等

function contentFun (dot) {
  var dotStr = "";
  if (dot) {
    dotStr = dot.replace(/<[^>]+>|&[^>]+;/g,"").trim();
    dotStr = dot.replace(/<[^>]+>/g, "");
    dotStr = dotStr.replace(/&ldquo;/g, "");
    dotStr = dotStr.replace(/&rdquo;/g, "");
    dotStr = dotStr.replace(/&nbsp;/g, "");
  }
  return dotStr;
};

轉時間戳爲 yyyy-mm-dd h:m

function formateTime(unixtime){
	if(!unixtime){
    	return "/"
	}
  	var dateTime = new Date(parseInt(unixtime))
	var year = dateTime.getFullYear();
  	var month = dateTime.getMonth() + 1;
  	var day = dateTime.getDate();
  	var hour = dateTime.getHours();
  	var minute = dateTime.getMinutes();
  	var second = dateTime.getSeconds();
  	unixtime = year + '-' + ((month < 10) ? ('0' + month) : month) + '-' + ((day < 10) ? ('0' + day) : day) + ' ' + ((hour < 10) ? ('0' + hour) : hour) + ':' + ((minute < 10) ? ('0' + minute) : minute);
  	return unixtime;}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章