使用日期选择器在按钮单击上添加日期范围

发布于 2024-12-18 19:15:38 字数 202 浏览 6 评论 0原文

我正在尝试通过单击按钮打开带有日期选择器的日历,并在选择时将日期放入同级文本框中。我需要能够对两个不同的文本框执行此操作。

这是我到目前为止所拥有的。

http://jsfiddle.net/dan_vitch/zEper/

I am trying open a calendar with datepicker on button click, and have the date go into the sibling text box when chosen. I need to be able to do this for two different text boxes.

Here is what I have so far.

http://jsfiddle.net/dan_vitch/zEper/

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

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

发布评论

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

评论(1

榆西 2024-12-25 19:15:39

您需要使用该 jsfiddle 加载 jQuery UI。尝试以下操作:

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

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

和您的 JS:

$(".datepicker").datepicker({
    showOn: "button",
    buttonImage: "link to your button here",
    buttonImageOnly: true
});

需要注意的事项:您不需要添加按钮,日期选择器将为您执行此操作 - 您需要添加指向按钮图像的链接。如果您不喜欢这个,那么您可以删除 bottonImage 引用。

所有这些都取自 jQuery datepicker UI 文档 此处

编辑:
修复了 html 元素的结束标签,已在 jsfiddle 此处 中修复

You need to load the jQuery UI with that jsfiddle. Try the following:

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

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

And your JS:

$(".datepicker").datepicker({
    showOn: "button",
    buttonImage: "link to your button here",
    buttonImageOnly: true
});

Things to note: you don't need to add the button, the datepicker will do that for you - you'll need to add a link to a button image. If you don't like this then you could just remove the bottonImage reference.

All of this has been taken from the jQuery datepicker UI documentation here

EDIT:
Fixed up closing tags for html elements, fixed in jsfiddle here

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