时间格式需要添加到我的javascript中 [英] time format need to be add in my javascript
本文介绍了时间格式需要添加到我的javascript中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文本框只能包含数字值...所以我在下面添加了此功能
the textbox must contain only numeric values...So i added this function given below
function nummins(evt) {
var vlr;
var vlr = (window.event) ? event.keyCode : evt.which;
if ((vlr >= 48 && vlr <= 57) || vlr == 8) {
return true;
}
else {
alert("Time should be a Numeric Value");
return false;
}
}
它给了我正确的输出...
但是我的问题是在此函数中,我想要12小时时间格式的代码,即文本框值必须为1到12 ....
谁能帮我....
It gives me correct output...
But my problem is in this function I want a code for 12hr time format i.e.,the textbox value must be 1 to 12....
Can anyone help me....
推荐答案
在返回true之前,添加以下代码
对该函数再加上一个参数以引用当前对象,即文本框
Before return true, add the following code
Take one more argument to this function to refer current object i.e. textbox
function nummins(evt,this) {
var vlr;
var vlr = (window.event) ? event.keyCode : evt.which;
if ((vlr >= 48 && vlr <= 57) || vlr == 8) {
var num=Number(this.value);
if(num>12)
{
return false;
}
else
{
return true;
}
}
else {
alert("Time should be a Numeric Value");
return false;
}
}
it might be useful,
function nummins(evt,val) {
var vlr;
var vlr = (window.event) ? event.keyCode : evt.which;
if ((vlr >= 48 && vlr <= 57) || vlr == 8) {
if(val<13)
{
return true;
}
else
{
return false;
}
}
else {
alert("Time should be a Numeric Value");
return false;
}
}
<input type="text" id="txt" onkeypress="return nummins(evt,this.value)"></input>
这篇关于时间格式需要添加到我的javascript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文