转码和解码

//内容需要转码才能传入后台,这是转码方法
function HTMLEncode(html) {
var temp = document.createElement("div");
(temp.innerText != null) ? (temp.innerText = html) : (temp.textContent = html);
var output = temp.innerHTML.replace(/\n/g, "<br>");
temp = null;
return output;
}

//解码
function HTMLDecode(text) {
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
}

 

// 格式化js时间
function FormatDateTime(obj, IsMi) {
var myDate = new Date(obj);
var year = myDate.getFullYear();
var month = ("0" + (myDate.getMonth() + 1)).slice(-2);
var day = ("0" + myDate.getDate()).slice(-2);
var h = ("0" + myDate.getHours()).slice(-2);
var m = ("0" + myDate.getMinutes()).slice(-2);
var s = ("0" + myDate.getSeconds()).slice(-2);
var mi = ("00" + myDate.getMilliseconds()).slice(-3);
if (IsMi == true) {
return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
}
else {
return year + "-" + month + "-" + day;
}
};

posted @ 2017-06-21 10:42  领悟.海洋  阅读(270)  评论(0编辑  收藏  举报