2011-05-09 211 views

回答

3

JS中沒有這樣的幫助函數。您可以使用生成相當隨機哈希:

function hex(n){ 
n = n || 16; 
var result = ''; 
while (n--){ 
    result += Math.floor(Math.random()*16).toString(16).toUpperCase(); 
} 
return result; 
} 

你可以修改它形成一個GUID:

function generateGuid(){ 
var result = '', n=0; 
while (n<32){ 
    result += (~[8,12,16,20].indexOf(n++) ? '-': '') +  
      Math.floor(Math.random()*16).toString(16).toUpperCase(); 
} 
return result; 
} 
相關問題