<html>
<input type="button" id="btnSearch" value="Search" onclick="GetValue();" />
<p id="message" ></p>
<script>
function GetValue()
{
var myarray= new Array("item1","item2","item3");
var random = myarray[Math.floor(Math.random() * myarray.length)];
//alert(random);
document.getElementById("message").innerHTML=random;
}
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
这是代码,当我生成一个随机单词让我们说"item1"显示,我怎么能在它下面添加一个按钮,当我点击它复制"item1"