weixin_精慕门1524561
2020-12-09 10:55
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
function MATH(){
var num=Math.round(Math.random()*999);
document.getElementById("text1").value = num;
}
</script>
</head>
<body>
<from>
<input type="text" name="text" id="text1">
<input type="button" name="button" value="刷新" onclick="MATH()">
</from>
</body>
</html>
function MATH(){
var num=Math.round(Math.random()*999);
var str = num > 99 ? num : (num > 9 ? '0' + num : '00' + num)
document.getElementById("text1").value = str;
}
额..
function MATH(){
var num=Math.round(Math.random()*999);
var str;
if(num > 99){
str = num
}else if(num > 9 && num <= 99){
str = '0' + num
}else{
str = '00' + num
}
document.getElementById("text1").value = str;
}
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题