我的页面上有一个bootstrap datetimepicker元素。我想在不直接单击输入字段的情况下打开该元素上的日历。我什么都试过了,可以点击事件来打开日历。
元素:
<div class="input-group date basedatefield">
<input type="text" name="basefield" autocomplete="off" readonly="" class="form-control" id="id_basefield" dp_config="{"id": "dp_37", "picker_type": "DATE", "linked_to": null, "options": {"showClose": false, "showClear": true, "showTodayButton": false, "format": "MM/DD/YYYY", "useCurrent": false, "ignoreReadonly": true, "keepInvalid": true}}">
<div class="input-group-addon input-group-append" data-target="#basedatetimepicker1" data-toggle="datetimepickerv">
<div class="input-group-text"><i class="glyphicon glyphicon-calendar"></i></div>
</div>
</div>
我试过这些,但他们不会模拟点击和/或打开日历在这个字段
document.getElementById('id_basefield').click();
document.getElementsByClassName('basedatefield')[0].click();
document.getElementsByClassName('input-group')[0].click();
库有一个可用的show
方法:
https://bootstrap-datepicker.readthedocs.io/en/latest/methods.html显示
我认为你应该这样做:
$('.datepicker').datepicker('show');