如何使数据输入为只读,但显示日历? [英] How to make data input readonly, but showing calendar?

查看:76
本文介绍了如何使数据输入为只读,但显示日历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在任何地方都找不到解决方案.我想允许用户在单击输入时看到日历,但是当用户尝试更改值时,它不应更改(或立即更改为开始时的值).

I can't find any solution for this anywhere. I would like to allow user to see calendar when clicking on my input, but when user will try to change the value, it shouldn't change (or immediately change back for value, what was at the beggining).

Readonly 属性会删除日历,因此我尝试以其他方式执行此操作,例如使用 onchange/onclick 函数在事件后恢复我的值,但该值无论如何都在更改

Readonly attribute removes calendar, so I was trying to do it different ways like use onchange/onclick functions to restore my value after event, but the value was changing anyway.

所以现在我的输入看起来像这样:

So for now my input looks like this:

<input class='test' type='date' value='2020-06-04' onkeydown='return false' >

因此,至少用户不能使用键盘更改我的输入值.你能帮我吗?

So at least user can't change value of my input using keyboard. Could you help me?

推荐答案

您可能会尝试设置时间限制

You might try to set a time limit

<html>
<body>
<input type="date" value="2020-06-04">
<input type="date" value="2020-06-04" min="2020-06-04" max="2020-06-04">

</body>
</html>

这篇关于如何使数据输入为只读,但显示日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆