Datepicker:输入错误时恢复为上一个值 [英] Datepicker: revert to last value on incorrect input
本文介绍了Datepicker:输入错误时恢复为上一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大多数验证插件仅显示错误消息.但是,我希望(datepicker)完全避免输入不正确的值,而自动恢复为最后一个正确的值(不是页面加载时的初始值,而是最后一个正确的值).
Most validation plugins just show an error message. However, I would like (datepicker) to prevent entering incorrect values at all, automatically reverting to last correct value (not the intitial value on page load, but last correct one).
那怎么可能?
推荐答案
我刚刚找到了lastVal参数,这似乎是您想要的.尝试以下操作(答案在CoffeeScript中,但易于转换为JavaScript):
I just found the lastVal param which seems to be what your looking for. Try this (answer is in CoffeeScript but easy to translate to JavaScript):
$(".date1").datepicker.onClose = (dateText, inst) ->
if selectedDateIsValid(dateText, inst)
// Process new date
else
$(this).val(inst.lastVal)
window.alert("The selected day is invalid: ", dateText)
这篇关于Datepicker:输入错误时恢复为上一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文