当试图生成随机Unicode时,语法错误" Illegal"代币

时间:2014-12-27 05:27:58

标签: javascript unicode

当尝试制作随机Unicode(不是所有的unicodes,只是编号的那些)时,我收到此错误:

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字符?

1 个答案:

答案 0 :(得分:1)

var randUnicode = String.fromCharCode(“0x”+ getRandomInt(1000,9999).toString());

相关问题