0

我正在尝试使用 JQuery Ui 函数“Verfiy();” 在允许提交表格之前验证姓名、年龄、国家和日期字段是否已填写。

当用户点击“提交”时,应该调用验证函数,但是当我使用以下代码时,无论字段是否已完成,网页都会被定向到“谢谢”页面。它不显示错误消息。

<head>

...

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Wayne Nolting (w.nolting@home.com) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://www.javascriptsource.com -->

<!-- Begin

function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.name.value=="") {
themessage = themessage + " - Name";
}
if (document.form.age.value=="") {
themessage = themessage + " - Age";
}
if (document.form.country.value=="") {
themessage = themessage + " - Country";
}
if (document.form.date.value=="") {
themessage = themessage + " -  Date";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
//  End -->
</script>

</head>



<body>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>


...

 <input type="submit" value="Submit" onClick="verify()"/></div>
 <input type=reset value="Clear Form"><br>

...

</body>

任何见解将不胜感激。

安德鲁

4

1 回答 1

0

在这里,只需对标记进行一点调整。

<input type="submit" value="Submit" onClick="return verify()"/></div>
于 2013-09-26T04:57:10.647 回答