回复 楼主 maku1987
程序代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn. </script> <title>随机测试案例</title> </head> <body> <button onclick="foo2()" >随便问问</button> <button onclick="foo3()" >查看答案</button> <button onclick="foo4()" >隐藏答案</button><br><br> <div id=q2 style="display:none;"></div><br> <div id=a2 style="display:none;"></div> <script> idx=0; function foo2() { document.getElementById("a2").style="display:none;"; idx=Math.floor(Math.random()*6); lst=["1+1=?","2*8=?","36-89=?","789/2=?","45*89=?","36+987=?"]; lsta=[2,16,-53,394.5,4005,1023]; document.getElementById("q2").style="display:block;"; document.getElementById("q2").innerHTML=lst[idx]; } function foo3() { document.getElementById("a2").style="display:block;"; document.getElementById("a2").innerHTML=lsta[idx]; } function foo4() { document.getElementById("a2").style="display:none;"; } </script> </body> </html>