javascript - jQuery 日期选择器显示在页面底部 (Keith-Wood datepicker)

标签 javascript jquery css html

我遇到了 jquery datepicker(Keith-Wood)( http://keith-wood.name/datepick.html ) 的问题。它在 jquery 1.6.4 上运行良好,但在我迁移到 jQuery 1.10.2 之后,在使用日期选择器的每个实例中,小部件都出现在页面底部。

功能正常,只是位置搞砸了。

widget opening at the bottom

我需要打开小部件,在 DateAdded 部分下方写入。如果我切换回 jQuery 1.6.4,定位是正确的。这是使用 jQuery 1.6.4 时的屏幕截图

enter image description here

下面是我用来触发日历的函数。

function open_calendar()
{
    jQuery('.open_calendar').datepick(
    {
       beforeShow: function(input, inst)
       {
          inst.dpDiv.css({marginTop: -input.offsetHeight + 'px', marginLeft: input.offsetWidth + 'px'});
       },
       dateFormat: 'mm/dd/yy',
       rangeSelect: false,
       monthsToShow: [1,2],
       monthsOffset: 0,
       monthsToStep: 1,
       //supress the inline css used by jquery for div width
onShow:function(){
        jQuery('.datepick-multi').css({'width':'426'});
        jQuery('.datepick-popup').css({'z-index':'20000'});
        },
        constrainInput:false,
        showOnFocus:false,
        showTrigger:"<button type='button' title='Pick Date' style='padding:1px;' name='StartDatePicker' id='StartDatePicker'><img src='/images/calendarpicker.gif' alt='Pick Date' width='16' height='13'></button>"
        });
}

我需要让小部件的位置堆叠在触发它的文本框的正下方。

最佳答案

当您更新 jquery 时,您是否也从 http://keith-wood.name/datepick.html 更新了 jquery.plugin.js、jquery.datepick.js 和 jquery.datepick.css ?我认为旧版本的 datepick 插件可能与新版本的 jQuery 不兼容,但如果您更新 datepick 插件它应该可以工作。检查一下,它适用于 5.0 版的 datepick 插件和 1.10.2 版的 jQuery。

http://jsfiddle.net/t3kLr8d4/3/

HTML

<link rel="stylesheet" href="http://keith-wood.name/css/jquery.datepick.css" id="theme">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://keith-wood.name/js/jquery.plugin.js"></script>
<script src="http://keith-wood.name/js/jquery.datepick.js"></script>

<input type="text" id="date" />

CSS

/* Default styling for jQuery Datepicker v5.0.0. */
.datepick {
    background-color: #fff;
    color: #000;
    border: 1px solid #444;
    border-radius: 0.25em;
    -moz-border-radius: 0.25em;
    -webkit-border-radius: 0.25em;
    font-family: Arial,Helvetica,Sans-serif;
    font-size: 90%;
}
.datepick-rtl {
    direction: rtl;
}
.datepick-popup {
    z-index: 1000;
}
.datepick-disable {
    position: absolute;
    z-index: 100;
    background-color: white;
    opacity: 0.5;
    filter: alpha(opacity=50);
}
.datepick a {
    color: #fff;
    text-decoration: none;
}
.datepick a.datepick-disabled {
    color: #888;
    cursor: auto;
}
.datepick button {
    margin: 0.25em;
    padding: 0.125em 0em;
    background-color: #fcc;
    border: none;
    border-radius: 0.25em;
    -moz-border-radius: 0.25em;
    -webkit-border-radius: 0.25em;
    font-weight: bold;
}
.datepick-nav, .datepick-ctrl {
    float: left;
    width: 100%;
    background-color: #000;
    color: #fff;
    font-size: 90%;
    font-weight: bold;
}
.datepick-ctrl {
    background-color: #600;
}
.datepick-cmd {
    width: 30%;
}
.datepick-cmd:hover {
    background-color: #777;
}
.datepick-ctrl .datepick-cmd:hover {
    background-color: #f08080;
}
.datepick-cmd-prevJump, .datepick-cmd-nextJump {
    width: 8%;
}
a.datepick-cmd {
    height: 1.5em;
}
button.datepick-cmd {
    text-align: center;
}
.datepick-cmd-prev, .datepick-cmd-prevJump, .datepick-cmd-clear {
    float: left;
    padding-left: 2%;
}
.datepick-cmd-current, .datepick-cmd-today {
    float: left;
    width: 35%;
    text-align: center;
}
.datepick-cmd-next, .datepick-cmd-nextJump, .datepick-cmd-close {
    float: right;
    padding-right: 2%;
    text-align: right;
}
.datepick-rtl .datepick-cmd-prev, .datepick-rtl .datepick-cmd-prevJump,
.datepick-rtl .datepick-cmd-clear {
    float: right;
    padding-left: 0%;
    padding-right: 2%;
    text-align: right;
}
.datepick-rtl .datepick-cmd-current, .datepick-rtl .datepick-cmd-today {
    float: right;
}
.datepick-rtl .datepick-cmd-next, .datepick-rtl .datepick-cmd-nextJump,
.datepick-rtl .datepick-cmd-close {
    float: left;
    padding-left: 2%;
    padding-right: 0%;
    text-align: left;
}
.datepick-month-nav {
    float: left;
    background-color: #777;
    text-align: center;
}
.datepick-month-nav div {
    float: left;
    width: 12.5%;
    margin: 1%;
    padding: 1%;
}
.datepick-month-nav span {
    color: #888;
}
.datepick-month-row {
    clear: left;
}
.datepick-month {
    float: left;
    width: 15em;
    border: 1px solid #444;
    text-align: center;
}
.datepick-month-header, .datepick-month-header select, .datepick-month-header input {
    height: 1.5em;
    background-color: #444;
    color: #fff;
    font-weight: bold;
}
.datepick-month-header select, .datepick-month-header input {
    height: 1.4em;
    margin: 0em;
    padding: 0em;
    border: none;
    font-size: 100%;
}
.datepick-month-header input {
    position: absolute;
    display: none;
}
.datepick-month table {
    width: 100%;
    border-collapse: collapse;
}
.datepick-month thead {
    border-bottom: 1px solid #aaa;
}
.datepick-month th, .datepick-month td {
    margin: 0em;
    padding: 0em;
    font-weight: normal;
    text-align: center;
}
.datepick-month th {
    border: 1px solid #777;
}
.datepick-month th, .datepick-month th a {
    background-color: #777;
    color: #fff;
}
.datepick-month td {
    background-color: #eee;
    border: 1px solid #aaa;
}
.datepick-month td.datepick-week {
    border: 1px solid #777;
}
.datepick-month td.datepick-week * {
    background-color: #777;
    color: #fff;
    border: none;
}
.datepick-month a {
    display: block;
    width: 100%;
    padding: 0.125em 0em;
    background-color: #eee;
    color: #000;
    text-decoration: none;
}
.datepick-month span {
    display: block;
    width: 100%;
    padding: 0.125em 0em;
}
.datepick-month td span {
    color: #888;
}
.datepick-month td .datepick-other-month {
    background-color: #fff;
}
.datepick-month td .datepick-weekend {
    background-color: #ddd;
}
.datepick-month td .datepick-today {
    background-color: #f0c0c0;
}
.datepick-month td .datepick-highlight {
    background-color: #f08080;
}
.datepick-month td .datepick-selected {
    background-color: #777;
    color: #fff;
}
.datepick-month th.datepick-week {
    background-color: #777;
    color: #fff;
}
.datepick-status {
    clear: both;
    background-color: #ddd;
    text-align: center;
}
.datepick-clear-fix {
    clear: both;
}

Javascript

$('#date').datepick({
       beforeShow: function(input, inst)
       {
          inst.dpDiv.css({marginTop: -input.offsetHeight + 'px', marginLeft: input.offsetWidth + 'px'});
       },
       dateFormat: 'mm/dd/yy',
       rangeSelect: false,
       monthsToShow: [1,2],
       monthsOffset: 0,
       monthsToStep: 1,
       //supress the inline css used by jquery for div width
onShow:function(){
        jQuery('.datepick-multi').css({'width':'426'});
        jQuery('.datepick-popup').css({'z-index':'20000'});
        },
        constrainInput:false,
        showOnFocus:false,
        showTrigger:"<button type='button' title='Pick Date' style='padding:1px;' name='StartDatePicker' id='StartDatePicker'><img src='/images/calendarpicker.gif' alt='Pick Date' width='16' height='13'></button>"
});

关于javascript - jQuery 日期选择器显示在页面底部 (Keith-Wood datepicker),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25435290/

相关文章:

javascript - 使用 jquery(使用自定义代码)更改 div 类和 id 的基本语法

javascript - 无法使用 jQuery 动态添加表

html - 如何使用 css 网格填充列?

javascript - UpdatePanel 触发时图像不显示

javascript - 可以要求 Firebug 来运行我的网站吗?

javascript - 如何让 jquery 选择已使用 client.open 加载的 html 中的类

javascript - 使用 Jquery 以有限的间隔创建 DOM 元素

css - Bootstrap 图像自动调整大小在左列中不起作用

javascript - YayraBox 数据表 JavaScript CDN 与 Laravel 冲突

javascript - 图像隐藏,然后在鼠标移动时再次淡入、淡出和淡入