使用JavaScript限制TextBox中的+符号 [英] Restrict + symbol in TextBox using JavaScript

查看:73
本文介绍了使用JavaScript限制TextBox中的+符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的文本框不允许输入+符号,如何限制它

解决方案

这会阻止输入' +'在文本框中:

 <  !DOCTYPE     html  >  
< html >
< head >
< script >
window.onload = function(){
var keyupHandler = function(){
txtInput = this.value,
lastChar = txtInput.charAt(txtInput.length-1 )
if(lastChar =='+'){
this.value = txtInput.substr(0,txtInput.length-1);
}
返回;
};
document.getElementById('textbox1')。addEventListener('input',keyupHandler,false);
}
< / script >
< / head >
< body >
< 输入 id = textbox1 / >
< / body >
< / html > ;


hi,
my textbox does not allowed to type + symbol,how to restrict it

解决方案

This will prevent input of '+' in the textbox:

<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
    var keyupHandler = function() {
        txtInput = this.value,
        lastChar = txtInput.charAt(txtInput.length-1)
        if (lastChar=='+'){
              this.value = txtInput.substr(0, txtInput.length-1);
        }
        return;
    };
    document.getElementById('textbox1').addEventListener('input', keyupHandler, false);
}
</script>
</head>
<body>
<input id="textbox1" />
</body>
</html>


这篇关于使用JavaScript限制TextBox中的+符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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