没有输入的jQuery datepicker [英] jQuery datepicker without input

查看:84
本文介绍了没有输入的jQuery datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的网络应用程序,我想添加一些日期选择UI。

I've got a fairly complex web app that I'd like to add some date-picking UI to.

我遇到的问题是我无法从文档中弄清楚如何真正控制如何和何时显示日期戳。没有涉及到表单元素(不,我不会添加一个秘密表单字段),所以简单的开箱即用的方法根本不起作用。

The problem I'm running into is that I haven't been able to figure out from the docs how to really take control of how and when the datepicker appears. There are no form elements involved (and no, I'm not going to add a secret form field), so the dead-simple out-of-the-box approach simply won't work.

我希望有人可以提供一个模式的指导,让我以编程方式调用datepicker。我相信我知道如何使用datepicker的自定义事件来初始化和定位它,并在用户关闭时恢复所选择的值。我只是很难实例化一个日期戳,因为我没有配对一个元素。

I'm hoping someone can provide a little guidance on a pattern that allows me to invoke the datepicker programmatically. I believe I know how I'd use the datepicker's custom events to initalize and position it, and to recover the chosen value when the user dismisses it. I'm just having a hard time instantiating a datepicker, since I'm not pairing it to an element.

这是什么不是工作:

function doThing(sCurrent, event) { // sCurrent is the current value; event is an event I'm using for positioning information only
    var bIsDate = !isNaN( (new Date(sCurrent)).getTime() );

    jQuery.datepicker('dialog',
        (bIsDate ? new Date(sOriginal) : new Date()), // date
        function() { console.log('user picked a date'); }, // onSelect
        null, // settings (i haz none)
        event // position
    );

}

原因是jQuery.datepicker不是一个功能。 (我在做错了)

The reason is that "jQuery.datepicker" isn't a function. (I'm Doing It Wrong.)

我没有结婚到对话的方法 - 这只是我最好的猜测调用一个没有参考表单元素。

I'm not married to the 'dialog' approach -- it was just my best guess at invoking one without reference to a form element.

我正在使用jQuery 1.4.3和jQueryUI 1.8.6

I'm using jQuery 1.4.3 and jQueryUI 1.8.6

推荐答案

我阅读了datepicker代码,看起来像写的那样,datepicker 必须附加到input,div或span标签。

I read through the datepicker code, and it appears that, as written, the datepicker must be attached to an input, div, or span tag.

所以,如果你唯一的反对是使用表单元素,那么附加到div或span可能是你最好的选择,而在这里有一个如何做的例子: http://stackoverflow.com/a/1112135

So, if your only objection is to using a form element, then attaching to a div or span is probably your best bet, and there's an example of how to do that here: http://stackoverflow.com/a/1112135

如果你正在寻找一些另一种方式来控制datepicker,那么你可能需要扩展datepicker代码来做你想做的事情,如果你去那个路由,那么我建议你先看看dateincode代码中的_inlineDatepicker私有方法,是甲基od将datepicker附加到div或span标签。

If you're looking for some other way to control the datepicker, then you may have to extend datepicker code to do what you want it to do, and if you go that route, then I recommend starting by taking a look at the _inlineDatepicker private method in the datepicker code, which is the method that attaches the datepicker to a div or span tag.

这篇关于没有输入的jQuery datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆