function show(breakfast) { window.setTimeout(function() {$(breakfast).style.display = 'none';}, 5000); var array = new Array('油条', '大饼', '粢饭', '豆腐花', '生煎', '锅贴', '小笼', '小馄饨','葱油饼', '蛋饼'); $('breakfast').value = array[Math.floor(Math.random() * 10 + 1)]; } function equal(f, f1) { if (f1.value.strip().length == 0) { $('equal_error').innerHTML = ""; return true; } else if (f.value.strip() != f1.value.strip()) { $('equal_error').innerHTML = "买错了"; return false; } else { $('equal_error').innerHTML = "买对了"; return true; } }
<html> <head> <script type="text/javascript" src="js/prototype-1.6.0.3.js"> </script> <script type="text/javascript" src="js/validate.js"> </script> </head> <body οnlοad="show('breakfast');"> <form action="javascript:;"> <table> <tr> <td> 明天吃什么 <input type="text" size="20" style="display: ''" id="breakfast" readonly="true"> </td> </tr> <tr> <td> 吃的是 <input type="text" size="20" οnblur="equal(this, document.forms[0][0]);" /> <span id="equal_error"></span> </td> </tr> <tr> <td> <input type="reset" value="Reset"> </td> </tr> </table> </form> </body> </html>