当试图创建一个随机Unicode (不是来自所有的独角兽,只是编号的独角兽)时,我得到了以下错误:
Uncaught SyntaxError: Unexpected token ILLEGAL 使用此代码时:
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
// Error line:
var randUnicode = ('\u' + getRandomInt(1000, 9999).toString());这可能是因为javascript将\u视为Unicode的一个触发器,但在它之后需要一些东西。
如何在1000到9999之间随机生成Unicode字符?
发布于 2014-12-27 06:36:09
var randUnicode = String.fromCharCode("0x“+ getRandomInt(1000,9999).toString());
https://stackoverflow.com/questions/27664651
复制相似问题