防止时间选择器插件打开日历
我在旧问题中提出了以下问题:
我正在使用 jquery 的 timepicker 插件。一旦用户选择了日期+时间并单击“完成”按钮(基本上只是关闭对话框),我希望设置日期时间的文本框重新获得焦点(插件的当前行为是模糊焦点)。这是因为在此页面上我有一组文本框,并且它们的选项卡顺序是按顺序设置的。我需要日期时间文本框来重新获得焦点以继续选项卡顺序。否则 Tab 键顺序将从第一个文本输入重新开始,这对用户来说不方便。
我在下面得到了一个有效的答案
$('#MyDatepicker').datetimepicker({
onClose: function(dateText, inst) {
$('#MyDatepicker').focus();
}
});
,但这是我的新挑战:现在文本框重新获得焦点,日历再次打开。我该如何防止这种情况发生?
I asked the following in an old question:
I'm using the timepicker plugin for jquery. once users selected a date+time and click on the "Done" button, which basically just closes the dialog, i want the textbox where datetime is set to gain back focus (the current behavior of the plugin is to blur out focus). This is because on this page i have a set of textboxes and their tab orders are set sequentially. i need the datetime textbox to gain back focus to continue the tab order. otherwise the tab order will restart from the first text input which is inconvenient for the user.
I got back a working answer below
$('#MyDatepicker').datetimepicker({
onClose: function(dateText, inst) {
$('#MyDatepicker').focus();
}
});
but this is my new challenge: now the textbox has its focus back, the calendar opens again. how do i prevent that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,在尝试让它发挥作用后,我在周末思考了这个问题,当时我意识到也许最好的行为就是根本不把注意力放回去!想想您的用户,一旦他们明确选择了日期,为什么他们希望将注意力重新集中在同一字段上?因此,请将焦点设置到下一个输入。
http://jsfiddle.net/QwQwN/
我尝试使用日期选择器的 onClose 事件,但改变了焦点中途破坏了插件。我认为如果不修改实际的插件代码这是不可能的。
So I was thinking about this one over the weekend after messing around with trying to get it to work, when I realized that maybe the best behavior is not to set focus back at all! Thinking about your users, once they have explicitly selected a date, why would they want focus back on the same field? So instead set focus to the next input.
http://jsfiddle.net/QwQwN/
I tried using the onClose events of the date picker, but changing focus midstream broke the plugin. I dont think this is possible without modifying the actual plugin code.
你试过这个吗?
did you try this ?