4
我正在做一個窗體的簡單驗證。 JavaScript驗證工作正常,彈出警告框出現正確的錯誤,但點擊「確定」後,我會重新定向到下一頁。理想情況下,它應該保持在同一頁面上,以便用戶可以修改他/她的錯誤。請儘快幫助,這是一個學校項目,截止日期爲3天! 。:(在此先感謝JavaScript提醒錯誤消息
<script type = "text/javascript">
function show_alert() {
if (document.getElementById('time1').value == document.getElementById('time2').value) alert("ERROR! You cannot book the same timing twice!")
else if (document.getElementById('time1').value == document.getElementById('time3').value) alert("ERROR! You cannot book the same timing twice!")
else if (document.getElementById('time1').value == document.getElementById('time4').value) alert("ERROR! You cannot book the same timing twice!")
else if (document.getElementById('time1').value == "0") alert("ERROR! You cannot leave the first time slot blank!")
else {}
}
</script>
此外,`show_alert`需要返回true或false,指示是否應提交表單。 – casablanca 2011-01-22 17:27:25