【发布时间】:2023-03-22 07:04:01
【问题描述】:
我需要在div中显示随机单词而不重复单词。
示例: b 一种 C d
不是: b 一种 b C d d 一种 一种 c
$(document).ready(function($) {
words = ['a','b','c','d'];
function doSomething() {}
(function loop() {
var rand = Math.round(Math.random() * (3000 - 500)) + 500;
setTimeout(function() {
var thisWord = words[Math.floor(Math.random() * words.length)];
$("#container").append("<div class=\"conversation\">"+thisWord+"<div class=\"conversation\">");
doSomething();
loop();
}, rand);
}());
});
【问题讨论】:
-
这个问题基本上是stackoverflow.com/questions/26188735/…的重复。