uniqid() in javascript/jquery?

前端 未结 8 1845
孤城傲影
孤城傲影 2021-01-02 09:58

what\'s the equivalent of this function in javascript:

http://php.net/manual/en/function.uniqid.php

Basically I need to generate a random ID that looks like:

8条回答
  •  孤街浪徒
    2021-01-02 10:33

    Underscore.js has a uniqueid() method
    https://underscorejs.org/#uniqueId

    _.uniqueId([prefix])
    Generate a globally-unique id for client-side models or DOM elements that need one. If prefix is passed, the id will be appended to it.

    _.uniqueId('contact_');  
    => 'contact_104'
    

提交回复
热议问题