这个问题很直截了当,尽管我很难找到解决方法.

我正在使用一个jQuery-UI日期 Select 器和一个定制的"iOS风格开/关切换".此切换使用一些绝对定位的元素,这些元素当前显示在我的日期选取器的顶部.

see the ugly circle covering july 6th below...

在此处输入图像描述

the dirty way to do this (at least imo) is to write a style in one of my stylesheets, but I'd much rather use some javascript when the picker launches to get this done.

I've already tried

$('.date_field').datepicker(); 
$('.date_field').datepicker("widget").css({"z-index":100});

and

$('.date_field').datepicker({
    beforeShow: function(input, inst) { 
        inst.dpDiv.css({"z-index":100});
    }
});

但每次启动日期 Select 器时,z索引似乎都会被覆盖.

any help is appreciated!

推荐答案

Your JS code in the question doesn't work because jQuery resets the style attribute of the datepicker widget every time you call it.

An easy way to override its style's z-index is with a !important CSS rule as already mentioned in another answer. Yet another answer suggests setting position: relative; and z-index on the input element itself which will be automatically copied over to the Datepicker widget.

But, as requested, if for whatever reason you really need to set it dynamically, adding more unnecessary code and processing to your page, you can try this:

$('.date_field').datepicker({
    //comment the beforeShow handler if you want to see the ugly overlay
    beforeShow: function() {
        setTimeout(function(){
            $('.ui-datepicker').css('z-index', 99999999999999);
        }, 0);
    }
});

Fiddle

​I created a deferred function object to set the z-index of the widget, after it gets reset'ed by the jQuery UI, every time you call it. It should suffice your needs.

The CSS hack is far less ugly IMO, I reserve a space in my CSS only for jQuery UI tweaks (that's right above the IE6 tweaks in my pages).

Jquery相关问答推荐

Visual Studio - 将文本粘贴到 cshtml 中会删除文本

如何使用 jQuery 将表格的一行滚动到视图 (element.scrollintoView) 中?

jQuery 滚动到 Div

无法在被动事件侦听器中阻止默认值

如何在使用 jQuery 单击特定链接时打开 bootstrap 导航选项卡的特定选项卡?

对混合的字母/数字数组进行排序

如何使用给定的 url 判断图像是否存在?

jQuery scrollTop 在 Chrome 中不工作但在 Firefox 中工作

jQuery中追加的相反

Angular.js 在多个元素中重复

如何在 Jquery 中将 delay() 与 show() 和 hide() 一起使用

如何将参数传递给 JavaScript 中的匿名函数?

在 JQuery .trigger 上传递参数

使用 jquery 在 radio 上单击或更改事件

好处和.在本地托管 jQuery 的trap

如何使用 jQuery 隐藏 div?

判断文本框是否有空值

jquery 检测某些类的 div 已添加到 DOM

如何复制 pinterest.com 的绝对 div 堆叠布局

清除表jquery