【发布时间】:2020-05-21 20:16:14
【问题描述】:
我正在尝试在文本中插入一个Math.random(),这样它就会说“你的号码是”,然后是来自Math.random() 的号码。我可以从这行代码中看到它是可能的:alert("Copied the text: " + copyText.value);。它向您显示了您复制的内容,但我似乎无法弄清楚如何使用 Math.random() 来做到这一点。
function myFunction() {
var x = document.getElementById("demo")
x.innerHTML = Math.floor((Math.random() * 89999) + 10000);
}
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display a random 5 digit number.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<p>I want it to say something before the number like 'order #' and then the random number</p>
</body>
</html>
【问题讨论】:
标签: javascript html string concatenation