标签:time unique now() func number style var ++ get
如题,在JS中,利用Date.getTime()来生成唯一数字,用于ID
1 function uniqueNumber() { 2 var date = Date.now(); 3 4 if (date <= uniqueNumber.previous) { 5 date = ++uniqueNumber.previous; 6 } else { 7 uniqueNumber.previous = date; 8 } 9 10 return date; 11 } 12 13 uniqueNumber.previous = 0; 14 15 function ID(){ 16 return uniqueNumber(); 17 };
标签:time unique now() func number style var ++ get
原文地址:http://www.cnblogs.com/jlli/p/7879679.html