0
    $(document).ready(function () {

        $("#datepicker1").datepicker({

            minDate: 0,
            numberOfMonths: 2,
            onSelect: function (selected) {
                var minDate = $(this).datepicker('getDate');
                minDate.setDate(minDate.getDate() + 1);
                $("#datepicker2").datepicker("option", "minDate", minDate)
            }
        });

        $("#datepicker2").datepicker({
            numberOfMonths: 2,
            onSelect: function (selected) {
                $("#datepicker1").datepicker("option", "maxDate", selected)
            }
        });
    });

我有 2 个文本框(带有 jquery datepicker),它们是 datepicker1 和 datepicker2 以及一个搜索按钮。如果我点击按钮而不选择任何日期,我想显示一个标签,上面写着“请选择一个日期”这可能吗?

4

3 回答 3

0

Use RequiredFieldValidator to check for empty input fields.

Also refer to:

RequiredFieldValidator Class

于 2013-02-17T09:21:11.540 回答
0

well if you only want to validate against empty textbox then you could just go

Lets say your asp button has an id of "btnSubmit" hence you do this..

$('#btnSubmit').click(function (e) {
if (!valdateForm) {
e.preventDefault(); // this will prevent the button to submit so you can display error messages or do any other stuff you want. if validateForm returns true, then the form will submit as expected.
}


});

function validateForm() {
    if ($('#datepicker1').val().length == 0 || $('#datepicker2').val().length == 0) {
     return false;
    } else {return true;}
}
于 2013-02-17T09:23:48.867 回答
0

sure !

You can either use a plugin that does this for you. jQuery validation is a great pick http://docs.jquery.com/Plugins/Validation.

Or you could write it youself:

$("#search").click(function(e){
  if($("#datepicker2").val() === '' ||  $("#datepicker1").val() === ''){
    alert("Please provide a value for date");
    e.cancel();
  }
});

Code not tested, you might need to tweak it a bit :)

于 2013-02-17T09:25:36.573 回答