我对 datetimepicker 有以下问题。它适用于第一种形式,我只有一个日期字段,但它不适用于第二种形式。
Java 脚本:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/redmond/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/localization/messages_de.js"></script>
<script src="http://trentrichardson.com/examples/timepicker/jquery-ui-timepicker-addon.js"></script>
不起作用的表格:
<script>
// register_form geburtsdatum date
$().ready(function(){
$.validator.addMethod("dateTime", function (value, element) {
var stamp = value.split(" ");
var validDate = !/Invalid|NaN/.test(new Date(stamp[0]).toString());
var validTime = /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i.test(stamp[1]);
return this.optional(element) || (validDate && validTime);
}, "Please enter a valid date and time.");
$( "#termin1" ).datetimepicker({
changeMonth: true,
changeYear: true,
yearRange: "-0:+1",
dateFormat: 'yy-mm-dd'
});
$( "#termin2" ).datetimepicker({
changeMonth: true,
changeYear: true,
yearRange: "-0:+1",
dateFormat: 'yy-mm-dd'
});
$( "#termin3" ).datetimepicker({
changeMonth: true,
changeYear: true,
yearRange: "-0:+1",
dateFormat: 'yy-mm-dd'
});
});
$().ready(function(){
$("#send_termin").validate({
rules: {
termin1: {
required: true,
dateTime: true
},
termin2: {
required: true,
dateTime: true
},
termin3: {
required: true,
dateTime: true
},
},
errorElement: "span",
errorPlacement: function(error, element) {
error.insertAfter(element);
}
});
});
</script>
我使用以下 HTML 表单:
<form action="" id="send_termin" method="post">
<input type="hidden" name="action" value="view_message_add" />
<input type="hidden" name="sid" value="<?=$sid?>" />
<label for="termin1">Erste Termin:</label>
<input type="text" name="termin1" id="termin1" class="required"
value=""
size="30" />
<span></span>
<br />
<label for="termin2">Zweite Termin:</label>
<input type="text" name="termin2" id="termin2" class="required"
value=""
size="30" />
<span></span>
<br />
<label for="termin3">Dritte Termin:</label>
<input type="text" name="termin3" id="termin3" class="required"
value=""
size="30" />
<span></span>
<br />
<label for="message">Nachricht:</label>
<textarea rows="4" cols="50" maxlength="1000" id="Nachricht" name="Nachricht">Schreib hier kurze Nachricht für ihren Gegner. (Max 1000 Zeichen)
</textarea>
<br />
<input type="submit" value="Senden" />
</form>
知道为什么它不起作用吗?