在按下按钮时显示 jQueryUI 日期选择器,而不涉及输入字段
在 ASP.NET 项目中,我正在寻找一种方法,让 jQueryUI 日期选择器在按下按钮时出现,然后在选择日期时引发回发。我已经使用 此方法 使回发部分正常工作,但我无法让选择器在我想要的时候消失,或者在选择日期时正常运行。
我尝试过:
- 将选择器附加到按钮本身,但它在我选择之后和回发发生之前将按钮的文本设置为所选日期,这是我不想要的。
- 将选取器附加到按钮并将
altField
选项设置为位于浏览器窗口外部的,但它仍然设置选择日期时按钮的文本。
- 通过将其附加到
div
并在按钮的onclick
中创建它来使其内联。但根据 此论坛帖子,内联日期选择器的设计不显示“完成”按钮,并且我无法通过单击其外部来关闭它。- 我尝试将自己的“完成”按钮添加到日期选择器的按钮容器中(设置
showButtonPanel
时显示),但当月份或年份发生变化时,它就会消失,并且我没有发生任何事件。可以绑定似乎允许我将其添加回来。 - 我尝试将一个
mouseup
处理程序附加到文档正文,这样当我在日期选择器外部单击时,我可以关闭日期选择器,但是当我在日期选择器中单击时也会触发该处理程序,并且似乎会阻止选择器完全在工作。
- 我尝试将自己的“完成”按钮添加到日期选择器的按钮容器中(设置
这里最好的方法是什么?
In an ASP.NET project, I'm looking for a way to have a jQueryUI datepicker come up when I press a button, then cause a postback when a date is selected. I've gotten the postback part working using this method, but I'm having trouble either getting the picker to go away when I want it to or to behave properly when a date is selected.
I've tried:
- Attaching the picker to the button itself, but it sets the text of the button to the chosen date after I select and before the postback happens, which I don't want.
- Attaching the picker to the button and setting the
altField
option to an<input type='text' />
that's positioned outside the browser window, but it still sets the text of the button when a date is chosen. - Making it inline by attaching it to a
div
and creating it in theonclick
of the button. But according to this forum post, the inline datepicker by design doesn't show a Done button, and I can't dismiss it by clicking outside of it.- I tried adding a Done button of my own to the datepicker's button container (that shows up when
showButtonPanel
is set), but it goes away when the month or year changes and none of the events I can bind to seem to allow me to add it back. - I tried attaching a
mouseup
handler to the document body so I can dismiss the datepicker when I click outside it, but that triggers when I click in the datepicker too, and seems to prevent the picker from working at all.
- I tried adding a Done button of my own to the datepicker's button container (that shows up when
What's the best approach here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前使用过隐藏的
input
字段,并附加了一个日期选择器并取得了成功的结果:示例:
I've used a hidden
input
field before and attached a datepicker to it with successful results:Example: http://jsfiddle.net/7pttr/