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

I have the following div:<div class="input-group"><input type="hidden" id=

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745661070a4638840.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信