简体   繁体   English

防止用户在输入框中手动输入日期

[英]Prevent users from manually entering dates in input boxen

I am using the jQuery datepick plugin on two input boxes, and would like to prevent users of my Web site from manually entering dates in those input boxes. 我在两个输入框中使用了jQuery datepick插件,并希望防止我的网站用户在这些输入框中手动输入日期。 How could I do that? 我该怎么办?

I think I could cancel the onkeydown and onkeypress events, but it doesn't strike me as particularly elegant to do the same thing on two event handlers. 我认为我可以取消onkeydownonkeypress事件,但是在两个事件处理程序上执行相同的操作并没有让我感到特别优雅。 Is there any other means to achieve the same thing? 还有其他方法可以实现同一目标吗?

只需向这些输入字段添加readonly属性,这将阻止直接输入

在输入上设置“只读”值。

<input type='text' id='foo' readonly='readonly'>
<input type="text" readonly/>

应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM