我想询问提交后如何显示随机数?
var stampmonths = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
var thedate = new Date();
document.getElementById('ref').value = document.write(
stampmonths[thedate.getMonth()] +
thedate.getDate() +
thedate.getFullYear() +
thedate.getSeconds()
);
<form>
<input type="submit" id="ref" name="submit" value="submit" />
</form>
答案 0 :(得分:0)
你走了。在重新加载提交的表单时,以下脚本将更改按钮文本。
如果您不想重新加载页面,则需要使用jquery
等库来使用ajax
提交表单。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<input type="submit" id="ref" name="submit" value="submit" />
</form>
</body>
<script>
var stampmonths = new Array( "01","02","03","04","05","06","07","08","09","10","11","12");
var thedate = new Date();
document.getElementById('ref').value = stampmonths[thedate.getMonth()] + thedate.getDate() + thedate.getFullYear() + thedate.getSeconds();
</script>
</html>
您可以使用Math.Random
,如下所示,
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<input type="submit" id="ref" name="submit" value="submit" />
</form>
</body>
<script>
var stampmonths = new Array( "01","02","03","04","05","06","07","08","09","10","11","12");
var rnd = Math.floor((Math.random() * 9) + 1);;
var thedate = new Date();
document.getElementById('ref').value = rnd.toString() + stampmonths[thedate.getMonth()] + thedate.getDate() + thedate.getFullYear() + thedate.getSeconds();
</script>
</html>
答案 1 :(得分:0)
您需要使用提交按钮的点击事件中的preventDefault action取消提交操作,然后计算随机数并在页面上显示。
company_business_name