JavaScript: how to generate UUID for Internet Explorer 9?

家住魔仙堡 提交于 2019-12-04 05:56:44

问题


Does anyone know how to generate UUID/GUID for Internet Explorer?

I have code from Broofa at: http://www.broofa.com/2008/09/javascript-uuid-function/

this works fine on almost all the browsers except IE 9.


回答1:


this is how I do it:

window.Guid = function () {
    function part() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1).toUpperCase();
    };

    return {
        NewGuid: function () { return (part() + part() + "-" + part() + "-" + part() + "-" + part() + "-" + part() + part() + part()); },
        Empty: "00000000-0000-0000-0000-000000000000"
    };
} ();

now you can do:

Guid.NewGuid();  // new uuid
Guid.Empty;      // empty uuid


来源:https://stackoverflow.com/questions/8091561/javascript-how-to-generate-uuid-for-internet-explorer-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!