最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - JQuery Datepicker: show on input group addon button click - Stack Overflow

matteradmin6PV0评论

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')
});
Post a comment

comment list (0)

  1. No comments so far