• js 倒计时,转义


    function leftTimer(time) {
            var leftTime = (new Date(time)) - (new Date()); //计算剩余的毫秒数 
            var days = parseInt(leftTime / 1000 / 60 / 60 / 24, 10); //计算剩余的天数 
            var hours = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时 
            var minutes = parseInt(leftTime / 1000 / 60 % 60, 10); //计算剩余的分钟 
            var seconds = parseInt(leftTime / 1000 % 60, 10); //计算剩余的秒数 
            days = checkTime(days);
            hours = checkTime(hours);
            minutes = checkTime(minutes);
            seconds = checkTime(seconds);
            return days + "天" + hours + "小时" + minutes + "分" + seconds + "秒";
        }
    
        function checkTime(i) { //将0-9的数字前面加上0,例1变为01 
            if (i < 10) {
                i = "0" + i;
            }
            return i;
        }

    js转义和反转义

    //HTML反转义
    function HTMLDecode(text) { 
    var temp = document.createElement("div"); 
    temp.innerHTML = text; 
    var output = temp.innerText || temp.textContent; 
    temp = null; 
    return output; 
    } 
    var tagText = "<p><b>123&456</b></p>";
    var encodeText = HTMLEncode(tagText);
    console.log(encodeText);//&lt;p&gt;&lt;b&gt;123&amp;456&lt;/b&gt;&lt;/p&gt;
    console.log(HTMLDecode(encodeText)); //<p><b>123&456</b></p>
    
    
    
    //HTML转义
    function HTMLEncode(html) {
    var temp = document.createElement("div");
    (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
    var output = temp.innerHTML;
    temp = null;
    return output;
    }
    
    var tagText = "<p><b>123&456</b></p>";
    console.log(HTMLEncode(tagText));//&lt;p&gt;&lt;b&gt;123&amp;456&lt;/b&gt;&lt;/p&gt;
  • 相关阅读:
    MySQL学习(十二)
    MySQL学习(十一)
    MySQL学习(十)
    MySQL学习(九)
    MySQL学习(八)
    hlg1600线性代数中的矩阵问题【区间dp】
    HDU1556Color the ball【标号法||树状数组】
    hlg1481 Attack of the Giant n-pus【二分+二分图】
    0918
    20140913
  • 原文地址:https://www.cnblogs.com/xiaopanglian/p/9474886.html
Copyright © 2020-2023  润新知