gpt4 book ai didi

javascript - JQuery 验证仅适用于提交表单中的第一个元素。 [打算验证所有]

转载 作者:可可西里 更新时间:2023-11-01 02:29:32 25 4
gpt4 key购买 nike

The JQuery validation only works for the first element in the form submitted, Validation won't check for the 2nd one. Need to find out what is missing. Swap the input for text1 and date2, validation still works for the first one.

<!DOCTYPE HTML>
<html lang="en-US">
<head><title>
</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.5.1.min.js'></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://jquery-multifile-plugin.googlecode.com/svn-history/r16/trunk/jquery.MetaData.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/base/jquery-ui.css"/>

<script type="text/javascript">
$(document).ready(function () {
$("#form1").validate();

$(".date").datepicker({
changeYear: true,
dateFormat: 'dd/mm/yy',
minDate: new Date('1990/01/01'),
maxDate: '30Y'
});
});
function test() {
alert(document.getElementById("datetext").getAttribute("must"));
}
</script>
</head>
<body>
<form method="post" action="WebForm1.aspx" id="form1">
Text:<font color="red">* </font><input id="Text1" class="lvl {required:true,messages:{required:'blank not allowed.'}}" /><br />
Select Date2:<font color="red">* </font><input id="date2" class="date {required:true,messages:{required:'Required:Need to enter 2 date.'}}" readonly="true" /><br />
<input type="submit" value="Submit"/>
</form>
</body>
</html>

最佳答案

一定要包含 name归因于您的输入。我相信它使用 name属性来构建其验证字段列表,因为您没有指定 name属性,jquery 验证认为第二个字段与第一个字段同名。

例如,<input id="Text1" name="Text1" />

关于javascript - JQuery 验证仅适用于提交表单中的第一个元素。 [打算验证所有],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11549338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com