Automatically generating unique DOM ids?

前端 未结 4 2202
别那么骄傲
别那么骄傲 2020-12-18 22:33

When coding with JS and the DOM I find myself constantly needing to generate ids (or names) that have no purpose other than to group DOM elements together (or r

4条回答
  •  伪装坚强ぢ
    2020-12-18 22:51

    I agree with some of the commenters that there are probably better ways to do this, but a simple implementation of unique_id() you could use would be:

    return Math.random().toString(36);
    

提交回复
热议问题