在写代码中遇到的一些易忘知识点

                                     目录                                        

1.单行文本的溢出显示省略号

2.刷新页面

3.格式化时间

4.检索 indexOf()

5.数组元素的添加

 

 

 

 

 

 

 

 



 

1、单行文本的溢出显示省略号

overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;

2、刷新页面

window.location.reload(true) //浏览器重新从服务器请求资源,在http请求头中不会包含缓存标记。

3、格式化时间

Date.prototype.format = function(split) {
    split = split || "";

    if(split === 'time') {
        return _(this.getHours()) + ':' + _(this.getMinutes()) + ':' + _(this.getSeconds()); /*返回  时:分:秒*/
    } else {
        var month = this.getMonth() + 1;
        month = month < 10 ? "0" + month : month;
        var day = this.getDate();
        day = day < 10 ? "0" + day : day;

        return this.getFullYear() + split + month + split + day; /*返回  年月日*/
    }
}

4、检索 indexOf()

indexOf() 方法对大小写敏感!
如果要检索的字符串值没有出现,则该方法返回 -1。

5、数组元素的添加 

arrayObj.push([item1 [item2 [. . . [itemN ]]]]); // 将一个或多个新元素添加到数组结尾,并返回数组新长度  
arrayObj.unshift([item1 [item2 [. . . [itemN ]]]]); // 将一个或多个新元素添加到数组开始,数组中的元素自动后移,返回数组新长度  
arrayObj.splice(insertPos,0,[item1[, item2[, . . . [,itemN]]]]); //将一个或多个新元素插入到数组的指定位置,插入位置的元素自动后移。 

 

posted @ 2016-09-08 10:56  Ann丶  阅读(230)  评论(0编辑  收藏  举报