按del键时,文本框的onkeypress在IE中不起作用 [英] onkeypress of textbox not working in IE when del key is pressed

查看:149
本文介绍了按del键时,文本框的onkeypress在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在gridview控制问题中有一个asp.net文本框,即时通讯是当用户从键盘上按DEL键操作其在其他键上时,"onkeypress"事件在IE中不起作用,我的代码如下

Hi all,

i have a asp.net textbox in gridview control problem im having is that "onkeypress" event is not working in IE when user pres DEL key from keyboard its working on other keys my code is as follows

<asp:TextBox CssClass="InputBox"  onkeypress="return isValidKey(event)" ID="txtRefundAmount" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Amount") %>'></asp:TextBox>





function isValidKey(e) {
            return false;
        }



我只是想防止用户修改文本框值.这可以通过设置文本框属性readonly = true或enable = false来完成,但是在我的情况下,另一个Java脚本函数正在更新此文本框的值,并且如果我将其设置为只读或禁用运行时的更新值,则在保存数据时不会在服务器上发布



i just simply want to prevent user from modifying textbox value. this can be done by setting textbox property readonly=true or enable=false but in my case another java script function is updating value this textbox and if i make it readonly or disable updated value at run time is not posted on server when saving data

推荐答案

尝试此

try this

function isValidKey(e) { 
    
  var charCode = e.keyCode || e.which;     
  if (charCode == 8 || charCode == 46)         
      return false;      

return true; 
}  

<input id="tb_box" onkeydown="return isValidKey(event)" type="text" /> 


这篇关于按del键时,文本框的onkeypress在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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