【发布时间】:2020-10-04 14:16:02
【问题描述】:
我的以下代码运行良好,但我想验证文本框 TBMonday 以强制用户输入指定的模式。我如何使用 Javascript 来做到这一点(请我不想使用 input type='time')
<input type="text" id="TBMonday" size="7" placeholder="hh:mm-hh:mm" pattern="(2[0-4]|1[0-9]|[1-
9])\:(5[0-9]|4[0-9]|3[0-9]|2[0-9]|1[0-9]|[0-9])-(2[0-4]|1[0-9]|[1-9])\:(5[0-9]|4[0-9]|3[0-
9]|2[0-9]|1[0-9]|[0-9])" onKeyUp="TBMondayEl();">
<input type="text" id="TBMonday2" size="7">
<script>
function TBMondayEl()
{
document.getElementById('TBMonday2').value = document.getElementById('TBMonday').value;
}
</script>
【问题讨论】:
-
这能回答你的问题吗? a way to check validity of HTML5 forms?
标签: javascript