如何在文本框中进行keppress时为允许tab键编写javascript [英] how to write javascript for allow tab key when keppress in textbox
问题描述
嗨我的aspx页面中有文本框。
允许字母和退格按钮工作正常但是tab键不起作用。我这样的剧本
函数AllowAlphabet(e){
isIE = document.all? 1 : 0
keyEntry =!isIE? e.which: event .keyCode;
if (((keyEntry > = ' 65')&&(keyEntry < = ' 90'))||((keyEntry > = ' 97')&&(keyEntry < = ' 122'))||(keyEntry == ' 46')|| keyEntry == ' 8' || keyEntry == ' 9')
返回 true ;
else
return false < /跨度>;
}
< asp:TextBox ID =txtempfirstnamerunat =serverclass =textboxTabIndex =1align =right onkeypress =返回AllowAlphabet(事件)>
但是tab键无效..请帮帮我
谢谢
你可以看到是否按下了TAB键方式,
< html >
< head >
< / head >
< 正文 >
< ; script type < span class =code-keyword> = text / javascript >
function AllowAlphabet(e)
{
if (event.keyCode == 9 )
{
// TAB被按下keyCode = 9表示TAB键
返回 false ;
}
其他
{
返回 真跨度>;
}
}
< / script >
< 输入 type = text id = txtName onkeydown = return AllowAlphabet(event) >
< / body >
< / html >
请检查您的代码和我放在这里的差异主要是我使用了onkeydress事件,你使用了onkeypress事件。
如果这对你有帮助,请告诉我。
试试这个代码!!
函数AllowAlphabet(e ){
keyEntry =(e.keyCode)? e.keyCode:e.which;
if (((keyEntry > = ' 65')&&(keyEntry < = ' 90'))||((keyEntry > = ' 97')&&(keyEntry < = ' 122'))||(keyEntry == ' 46')|| keyEntry == ' 8' || keyEntry == ' 9')
返回 true ;
else
return false < /跨度>;
} < / script > < /跨度>
hi i have textbox in my aspx page.
its allow the alphabets and backspace button is working fine but tab key is not working. my script like this
function AllowAlphabet(e) {
isIE = document.all ? 1 : 0
keyEntry = !isIE ? e.which : event.keyCode;
if (((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || keyEntry == '8' || keyEntry == '9')
return true;
else
return false;
}
<asp:TextBox ID="txtempfirstname" runat="server" class="textbox" TabIndex="1" align="right" onkeypress="return AllowAlphabet(event)">
but tab key not working.. please help me
thanks
Hi,
You can catch whether a TAB key was pressed in following way,
<html> <head> </head> <body> <script type="text/javascript"> function AllowAlphabet(e) { if (event.keyCode == 9) { //TAB is pressed keyCode = 9 for TAB key return false; } else { return true; } } </script> <input type="text" id="txtName" onkeydown="return AllowAlphabet(event)"> </body> </html>
Please check the difference in your code and one I have put here is mostly I have used onkeydown event where you used a onkeypress event.
Let me know if that helps you.
Try this code !!
function AllowAlphabet(e) { keyEntry = (e.keyCode) ? e.keyCode : e.which; if (((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || keyEntry == '8' || keyEntry == '9') return true; else return false; }</script>
这篇关于如何在文本框中进行keppress时为允许tab键编写javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!