既然是根據(jù)當(dāng)前的時(shí)間,那么我們第一步就是獲取當(dāng)前時(shí)間,然后拼接一個(gè)隨機(jī)數(shù),這樣便實(shí)現(xiàn)了隨機(jī)生成一個(gè)流水號(hào),注意由于要求每個(gè)流水號(hào)都是獨(dú)一無二的,生成后提交的過程中還是需要驗(yàn)證當(dāng)前的流水號(hào)是否存在,如果存在則需要提示用戶或者再次生成。
// 根據(jù)當(dāng)前時(shí)間和隨機(jī)數(shù)生成流水號(hào) randomNumber() { const now = new Date() let month = now.getMonth() + 1 let day = now.getDate() let hour = now.getHours() let minutes = now.getMinutes() let seconds = now.getSeconds() month = this.setTimeDateFmt(month) hour = this.setTimeDateFmt(hour) minutes = this.setTimeDateFmt(minutes) seconds = this.setTimeDateFmt(seconds) return now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math.round(Math.random() * 89 + 100)).toString() }
當(dāng)前標(biāo)題:用JS實(shí)現(xiàn)根據(jù)當(dāng)前時(shí)間隨機(jī)生成流水號(hào)或者訂單號(hào)-創(chuàng)新互聯(lián)
本文URL:http://www.chinadenli.net/article36/doehpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站改版、網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容