JavaScript String.fromCharCode() 函数详解

    xiaoxiao2021-03-25  105

    String.fromCharCode()函数用于从一些Unicode字符值中返回一个字符串。

    该函数属于String对象,所有主流浏览器均支持该函数

    语法

    String.fromCharCode( [code1 [, code2 [, codes... ]]] )

    String.fromCharCode()函数属于静态函数,而且只能够通过全局String对象进行调用,不能通过String对象的实例进行调用。

    参数

    参数 描述 code1 可选/Number类型要转换为字符串的Unicode字符值1。 code2 可选/Number类型要转换为字符串的Unicode字符值2。 codes 可选/Number类型要转换为字符串的Unicode字符值,可以有多个。

    返回值

    String.fromCharCode()方法的返回值为String类型,其返回值为Unicode数值所表示的字符串。

    如果没有传入任何参数,则返回空字符串""。

    示例&说明

    document.writeln( String.fromCharCode( 65, 66, 67, 68, 69, 70, 71 ) ); // ABCDEFG document.writeln( String.fromCharCode( 78 ) ); // N document.writeln( String.fromCharCode( 20013, 22269 ) ); // 中国 document.writeln( String.fromCharCode() ); // (空字符串)

    运行代码

    转载请注明原文地址: https://ju.6miu.com/read-33220.html

    最新回复(0)