今天绵阳动力网络为你介绍JavaScript返回0-1之间随机数的方法,涉及javascript中Math对象random方法的使用技巧,可以返回一个0-1之间随机数。非常具有实用价值,需要的朋友可以参考下:
<!DOCTYPE html>
<html>
<body>
<p id="demo"> Click the button to display a random number. </p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
document.getElementById("demo").innerHTML=Math.random();
}
</script>
</body>
</html>