js/jQuery
[javascript] guid 만들기
건빵쥔광이씨
2017. 12. 7. 10:05
html
<button type="button" id="btn_create">생성</button> <input type="text" id="guid" value="" />css
#guid { width:500px; }javascript
var _guid = {}; _guid.get = function() { return _guid.s4() + _guid.s4() + _guid.s4() + _guid.s4() + _guid.s4() + _guid.s4() + _guid.s4() + _guid.s4(); } _guid.s4 = function() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } $('#btn_create').on('click', function(){ $('#guid').val(_guid.get()); });
demo : jsfiddle link