从日期选择器的按钮面板中删除默认按钮

发布于 2024-12-19 05:06:25 字数 561 浏览 5 评论 0原文

我想保留按钮面板,但我不想要“今天”或“完成”按钮

jquery:

$(document).ready(function () {
       $(".datepicker").datepicker({
            showOn: "button",
            buttonText: "Date",
            showButtonPanel: true
        });
});

html:

<div>
    <label for="start">Start</label>
    <input id="start" type="text" class="datepicker"/>
</div>

<div>
    <label for="end">End</label>
    <input id="end" type="text" class="datepicker"/>
</div>

I want to keep the button panel but I do not want the 'Today' or 'Done' buttons

jquery:

$(document).ready(function () {
       $(".datepicker").datepicker({
            showOn: "button",
            buttonText: "Date",
            showButtonPanel: true
        });
});

html:

<div>
    <label for="start">Start</label>
    <input id="start" type="text" class="datepicker"/>
</div>

<div>
    <label for="end">End</label>
    <input id="end" type="text" class="datepicker"/>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-12-26 05:06:25

更新

显然我提供的解决方案有点过时了。请参阅下面的答案以获取有效的修复:https://stackoverflow.com/a/24806307/959041


您应该添加该选项

showButtonPanel: false

使您可以

$("#test").datepicker({
    showButtonPanel: false
});

更新

删除按钮,但能够添加其他按钮,您可以使用beforeShow事件。所以你有类似的东西,

$("#test").datepicker({
    beforeShow: function() {
        $(".ui-datepicker-buttonpane")
            .html('')
            .append("<button>new button</button>");
    }
});

请参阅 http://jqueryui.com/demos/datepicker/#buttonbar 用于文档

UPDATE

apparently the solution I provided is kinda outdated. Please see the answer below for a working fix: https://stackoverflow.com/a/24806307/959041


you should add the option

showButtonPanel: false

so you have

$("#test").datepicker({
    showButtonPanel: false
});

UPDATE

to remove the buttons but be able to add other buttons you can use the beforeShow event. So you have something like

$("#test").datepicker({
    beforeShow: function() {
        $(".ui-datepicker-buttonpane")
            .html('')
            .append("<button>new button</button>");
    }
});

see http://jqueryui.com/demos/datepicker/#buttonbar for the documentation

夏花。依旧 2024-12-26 05:06:25

我刚刚接受了之前的答案并找到了如何使其工作,但这看起来很难看。

基本上我添加的是 setTimeout ,因为按钮窗格的内容似乎是在 beforeShow 事件之后呈现的:

$('.datepicker').datepicker({
    showOn: 'button',
    buttonText: 'Date',
    showButtonPanel: true,
    beforeShow: function (){
        setTimeout(function() {
         $(".ui-datepicker-buttonpane")
            .html('')
            .append("<button>new button</button>");
        }, 1)
    }
});

http://jsfiddle。净/zEper/278/

I just took previous answer and found how to make it work, but this looks ugly.

Basically what I added is setTimeout as it seems that content of buttons pane is rendered after beforeShow event:

$('.datepicker').datepicker({
    showOn: 'button',
    buttonText: 'Date',
    showButtonPanel: true,
    beforeShow: function (){
        setTimeout(function() {
         $(".ui-datepicker-buttonpane")
            .html('')
            .append("<button>new button</button>");
        }, 1)
    }
});

http://jsfiddle.net/zEper/278/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文