admin管理员组

文章数量:1026989

I have the following div:

            <div class="input-group">
                <input type="hidden" id="datepicker">
                <input type="text" id="input_date" class="form-control" value="" readonly='readonly'>
                <span class="input-group-addon" id="input_btn_calendar"><i class="fa fa-calendar"></i></span>
            </div>

And the following JQuery call:

    var today = new Date();
    $("#input_date").datepicker({
        changeYear: false,
        numberOfMonths: 1,
        altFormat: "yy-mm-dd",
        altField: "#datepicker",
        minDate: today,
        onSelect : function () {
            var inputdate = $.datepicker.parseDate('yy-mm-dd', $("#datepicker").val());
        }
    }).datepicker("setDate",today);

This makes the datepicker appear correctly when I press the text field. However, I also want it to show up when I click the input_btn_calendar button inside the acpanying span.

I've tried this:

    $("#input_btn_calendar").click(function() {
        $("input_date").datepicker('show')
    });

But unfortunately, that does nothing. What am I missing?

I have the following div:

            <div class="input-group">
                <input type="hidden" id="datepicker">
                <input type="text" id="input_date" class="form-control" value="" readonly='readonly'>
                <span class="input-group-addon" id="input_btn_calendar"><i class="fa fa-calendar"></i></span>
            </div>

And the following JQuery call:

    var today = new Date();
    $("#input_date").datepicker({
        changeYear: false,
        numberOfMonths: 1,
        altFormat: "yy-mm-dd",
        altField: "#datepicker",
        minDate: today,
        onSelect : function () {
            var inputdate = $.datepicker.parseDate('yy-mm-dd', $("#datepicker").val());
        }
    }).datepicker("setDate",today);

This makes the datepicker appear correctly when I press the text field. However, I also want it to show up when I click the input_btn_calendar button inside the acpanying span.

I've tried this:

    $("#input_btn_calendar").click(function() {
        $("input_date").datepicker('show')
    });

But unfortunately, that does nothing. What am I missing?

Share Improve this question asked May 24, 2016 at 9:53 filpafilpa 3,6649 gold badges56 silver badges102 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

You have an invalid selector of $('input_date').

Try this instead,

$("#input_btn_calendar").click(function() {
    $("#input_date").datepicker('show')
});

I have the following div:

            <div class="input-group">
                <input type="hidden" id="datepicker">
                <input type="text" id="input_date" class="form-control" value="" readonly='readonly'>
                <span class="input-group-addon" id="input_btn_calendar"><i class="fa fa-calendar"></i></span>
            </div>

And the following JQuery call:

    var today = new Date();
    $("#input_date").datepicker({
        changeYear: false,
        numberOfMonths: 1,
        altFormat: "yy-mm-dd",
        altField: "#datepicker",
        minDate: today,
        onSelect : function () {
            var inputdate = $.datepicker.parseDate('yy-mm-dd', $("#datepicker").val());
        }
    }).datepicker("setDate",today);

This makes the datepicker appear correctly when I press the text field. However, I also want it to show up when I click the input_btn_calendar button inside the acpanying span.

I've tried this:

    $("#input_btn_calendar").click(function() {
        $("input_date").datepicker('show')
    });

But unfortunately, that does nothing. What am I missing?

I have the following div:

            <div class="input-group">
                <input type="hidden" id="datepicker">
                <input type="text" id="input_date" class="form-control" value="" readonly='readonly'>
                <span class="input-group-addon" id="input_btn_calendar"><i class="fa fa-calendar"></i></span>
            </div>

And the following JQuery call:

    var today = new Date();
    $("#input_date").datepicker({
        changeYear: false,
        numberOfMonths: 1,
        altFormat: "yy-mm-dd",
        altField: "#datepicker",
        minDate: today,
        onSelect : function () {
            var inputdate = $.datepicker.parseDate('yy-mm-dd', $("#datepicker").val());
        }
    }).datepicker("setDate",today);

This makes the datepicker appear correctly when I press the text field. However, I also want it to show up when I click the input_btn_calendar button inside the acpanying span.

I've tried this:

    $("#input_btn_calendar").click(function() {
        $("input_date").datepicker('show')
    });

But unfortunately, that does nothing. What am I missing?

Share Improve this question asked May 24, 2016 at 9:53 filpafilpa 3,6649 gold badges56 silver badges102 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

You have an invalid selector of $('input_date').

Try this instead,

$("#input_btn_calendar").click(function() {
    $("#input_date").datepicker('show')
});

本文标签: javascriptJQuery Datepicker show on input group addon button clickStack Overflow