js常用的代码片段 发表于 2017-06-28 | 阅读次数: ℃ 字数统计: 223 | 阅读时长 ≈ 1 自定义循环函数1234567891011121314const ff = function () { var arry = []; (function iterator(i) { if(i==4){ console.log("结束了"); console.log(arry); return; }; arry.push(i); iterator(i+1); })(0)};ff(); title 样式的改变123456789101112131415161718192021222324252627282930313233 var oldTitle = null;$(document).bind('mouseover mouseout mousemove',function(event){ var left = event.pageX , top = event.pageY; var ele = event.target; var title = ele.title; var type = event.originalEvent.type; if(type == 'mouseover'){ oldTitle = title; ele.title = ''; //if(title && title.length > 0){ if(title != null){ var showEle = $('<div></div>',{text:title,class:'showTitleBox'}).css({ position:'absolute', top:top+10, left:left, border:'1px solid #CCC', borderRadius:'5px', background:"infobackground", fontFamily:'SimHei' }) showEle.appendTo('body'); } }else if(type == 'mouseout'){ ele.title = oldTitle; $('.showTitleBox').remove(); }else if(type == 'mousemove'){ $('.showTitleBox').css({ top:top+10, left:left }) }}) 时间戳123456789101112131415161718function add0(m) { return m < 10 ? '0' + m : m};//时间戳function getLocalTime(nS) { // return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '); // return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " "); var ti = new Date(parseInt(nS) * 1000); var y = ti.getFullYear(); var m = ti.getMonth() + 1; var d = ti.getDate(); var h = ti.getHours(); var mm = ti.getMinutes(); var s = ti.getSeconds(); return y + '-' + add0(m) + '-' + add0(d) //+ ' ' + add0(h) + ':' + add0(mm);} 本文标题:js常用的代码片段 文章作者:cuijian 发布时间:2017年06月28日 - 17:06 最后更新:2018年07月02日 - 15:07 原始链接:http://www.cuijiajun.xin/常用代码片段.html 许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。 支持原创,你想给多少就多少! 打赏 微信支付 支付宝