generate random string for div id

后端 未结 12 735
旧时难觅i
旧时难觅i 2020-12-04 17:03

I want to display YouTube videos on my website, but I need to be able to add a unique id for each video that\'s going to be shared by users. So I put this toget

12条回答
  •  星月不相逢
    2020-12-04 18:04

    I really like this function:

    function guidGenerator() {
        var S4 = function() {
           return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
        };
        return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
    }
    

    From Create GUID / UUID in JavaScript?

提交回复
热议问题