如何通过调用js文件在文本框中设置数字输入? [英] How to set numeric entry in textbox by calling a js file ?
本文介绍了如何通过调用js文件在文本框中设置数字输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个js文件,在文本框中调用整数条目,如下所示:
I am having a js file which is called for integer entry in textbox as follows:
function Numeric_Text_KeyDown(event)
{
var iKeyCode = event.keyCode;
//alert(iKeyCode);
if ( (event.ctrlKey) || (event.altKey)) return false;
if (iKeyCode == 38 || iKeyCode == 40 || iKeyCode == 13 || iKeyCode == 9 ||
iKeyCode == 8 || iKeyCode == 46 ||iKeyCode == 39 ||iKeyCode == 37 ||
iKeyCode == 229 ||((iKeyCode > 47 && iKeyCode < 58) && !(event.shiftKey) ) ||
(iKeyCode > 111 && iKeyCode < 124) ||(iKeyCode > 95 && iKeyCode < 106))
{
if (iKeyCode == 38 || iKeyCode == 40 || iKeyCode == 13 || iKeyCode == 9) {
return true;
}
else if((iKeyCode > 47) && (iKeyCode < 58)){
return true;
}
}
else
{
return false;
}
}
在源代码中引用的js文件为
< script language =javascripttype = text / javascriptsrc =../ JS / Common.js>< / script>
代码落后
FtxtDate.Attributes.Add(onkeydown ,返回NumericText_KeyDown(事件););
但是文本框中的整数验证不起作用。
In source referred js file as
<script language="javascript" type="text/javascript" src="../JS/Common.js"></script>
Code behind
FtxtDate.Attributes.Add("onkeydown", "return NumericText_KeyDown(event);");
But Validation for integer in textbox not working.
推荐答案
您的代码没有任何错误。我可以非常完美地运行你的代码。错误可能在另一个javascript中,因此无效。
There is not any bug on your code. I can run your code very perfectly. The error can be in another javascript so that its not working.
这篇关于如何通过调用js文件在文本框中设置数字输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文