如何在每次点击时更改datetimepicker的z-index?

时间:2016-03-08 09:18:43

标签: javascript jquery html css datepicker

我发现datetimepicker默认z-index1,但对于我的网站,我需要z-index 9999。我在点击处理程序中使用jquery更改了值,但它仅适用于第一次单击。连续点击不起作用。这是为什么?

<td style="height: 40px;">
    <input type="text" class="datetimepicker" name="sdate" placeholder="Start Date" style="height: 39px; width: 260px;">             
</td>
<td style="height: 40px;">
    <input type="text" class="datetimepicker" name="edate" placeholder="End Date" style="height: 39px; width: 260px;">             
</td>
$(document).ready(function() {
    $('.datetimepicker').on('click', function(e) {
        e.preventDefault();
        $(this).datetimepicker({
            dateFormat: "yy-mm-dd",
            showTimezone: false,
            maskInput: true,
            timeFormat: "HH:mm:ss"
        }).focus();
        $('#ui-datepicker-div').css("z-index", 9999); //this is once time work
    });
});

2 个答案:

答案 0 :(得分:1)

在你的css文件中试试这个;

#ui-datepicker-div {
    z-index: 99999 !important;
}

答案 1 :(得分:1)

我找到了来自http://xdsoft.net/的固定代码,我刚刚添加了destroy函数。

$(document).ready(function() {
$('.datetimepicker').on('click', function(e) {
    e.preventDefault();
    $(this).datetimepicker({
        dateFormat: "yy-mm-dd",
        showTimezone: false,
        maskInput: true,
        timeFormat: "HH:mm:ss"
    }).focus();
    $('#ui-datepicker-div').css("z-index", 9999); //this is once time work
    $(this).datetimepicker("destroy");//this is solved my problem
});

});

相关问题