防止 jQuery timepicker 插件自动打开
有谁知道一种方法可以防止 jQuery timepicker 插件 在文本框聚焦时自动打开?该文档似乎没有提供一种方法,我目前正在查看源代码,看看是否可以添加该功能但是我是否忽略了实现此目的的简单方法?
Does anyone know of a method to prevent the jQuery timepicker addon from automatically opening up when the textbox is focused? The documentation doesn't seem to provide a way and I'm currently looking at the source seeing if I can add the functionality but have I overlooked a simple way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
单击按钮(以及聚焦输入框)时启动
datetimepicker
,并在选择器关闭时销毁该对象怎么样?示例: http://jsfiddle.net/william/NRH9r/
How about just initiate the
datetimepicker
upon the button clicked (as well as focus the input box), and destroy the object when the picker is closed?Example: http://jsfiddle.net/william/NRH9r/
尝试使用名为 unbind() 的 jquery 函数从 datetimepicker 中删除 onfocus 事件。然后,您可以在触发单击事件或您希望触发的任何其他事件时调用日期时间选择器的实例。另一种选择是调用触发 datetimepicker 的 onfocus 事件,并将事件对象传递到回调函数中。然后调用例如 event.preventDefault()。这将阻止 onfocus() 事件执行其通常执行的操作。
try to use a jquery function called unbind() to remove the onfocus event from the datetimepicker. You can then call an instance of the datetime picker when you fire a click event, or any other event you wish to fire. Another option would be to call the onfocus event that fires the datetimepicker, And pass in an event object into the callback function. Then call for example event.preventDefault(). This will prevent the onfocus() event from doing what it normally does.
由于 timepicker 是 jquery ui datepicker 的插件,因此您可以使用 showOn 选项指定使用按钮来触发它。请参阅此处的日期选择器示例。
以下是如何将其用于时间选择器的示例:
As the timepicker is an addon to the jquery ui datepicker, you can use the showOn option to specify that a button is used to trigger it. See the datepicker example here.
Here's an example of how this can be used for the time picker: