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).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…