Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript DOM中的随机文本?_Javascript_Reactjs_Ecmascript 6 - Fatal编程技术网

Javascript DOM中的随机文本?

Javascript DOM中的随机文本?,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,在常量中: <h2 className="logo" id="salt">{randomtext}</h2> 您应该使用Math.randomjs函数在定义的数组中有一个随机值,下面是一个简单的示例: 函数getRandomText(){ const txts=[“你好”,“再见”,“再见”,“嗯…” 让index=Math.round(Math.random()*(txts.length-1)) 返回txts[索引] } 让randomText=getRandomT

在常量中:

<h2 className="logo" id="salt">{randomtext}</h2>

您应该使用
Math.random
js函数在定义的数组中有一个随机值,下面是一个简单的示例:

函数getRandomText(){ const txts=[“你好”,“再见”,“再见”,“嗯…” 让index=Math.round(Math.random()*(txts.length-1)) 返回txts[索引] } 让randomText=getRandomText() $(“#rText”).html(随机文本)

function randomtext() { ??
}