限制文本框中只能输入数字 标签里写:onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"> <script type="text/javascript">function getEvent() { if (document.all) { return window.event; //for ie } func = getEvent.caller; while (func != null) { var arg0 = func.arguments[0]; if (arg0) { if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func = func.caller; } return null;}function doit(){ var ev = getEvent(); if(ev.keyCode < 48 || ev.keyCode > 57) return false;}</script><input type="text" id="txt" onkeydown="return doit()"> onkeypress = 'return /^\d$/.test(arguments[0].keyCode)'onblur = 'this.value = this.value.replace(/\D+/g, "")' 可以兼容ie,火狐,google浏览器么 这个只能适用于IE 但FF不行 不行啊。中文状态下,输入按shift或空格键就被输入进去了啊 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title></head><body><input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" /></body></html>试试这个 中文js禁止 不了的,可以加样式禁用输入法(chrome不会起作用)ime-mode:disabled; 那个禁用了输入法的imeMode适合firefox么???? zsx841021 ,我试了的,那个好像替换怎么没有效果啊。问下啊,onfaterpast是粘贴后出发的事件么??? 什么叫没有效果(onfaterpast是粘贴后出发的事件么???)对 private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (textBox3.SelectionStart == 0) { if (e.KeyChar.CompareTo( '0 ') == 0 || e.KeyChar.CompareTo( '0 ') < 0 || e.KeyChar.CompareTo( '9 ') > 0) { e.Handled = true; } } else { if (e.KeyChar.CompareTo( '0 ') < 0 || e.KeyChar.CompareTo( '9 ') > 0) { if (e.KeyChar != '\b ') e.Handled = true; } } } <input type="text"onkeypress = 'return /^\d$/.test(String.fromCharCode(event.keyCode))'oninput= 'this.value = this.value.replace(/\D+/g, "")'onpropertychange='if(!/\D+/.test(this.value)){return;};this.value=this.value.replace(/\D+/g, "")'onblur = 'this.value = this.value.replace(/\D+/g, "")'/>回复给你了,四事件组合,牛B轰轰的限制输入,至少兼容Firefox、IE、Chrome。 事件兼容<input type="text"onkeypress = 'return /^\d$/.test(String.fromCharCode(event.keyCode||event.keycode||event.which))'oninput= 'this.value = this.value.replace(/\D+/g, "")'onpropertychange='if(!/\D+/.test(this.value)){return;};this.value=this.value.replace(/\D+/g, "")'onblur = 'this.value = this.value.replace(/\D+/g, "")'/> <input type="text" this.value=value.replace(/[^\d]/g,'')\" onbeforepaste=\"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))/> 亲测,全部通过:<input type="text" name="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" /> 结贴给分! 我怎么测得还是出来了,右键贴的这么多人 帮看下我的问题http://topic.csdn.net/u/20111207/21/3bbfb031-0a42-4ed2-9de7-3ebac6dec751.html?57709 事件兼容<input type="text"onkeypress = 'return /^\d$/.test(String.fromCharCode(event.keyCode||event.keycode||event.which))'oninput= 'this.value = this.value.replace(/\D+/g, "")'onpropertychange='if(!/\D+/.test(this.value)){return;};this.value=this.value.replace(/\D+/g, "")'onblur = 'this.value = this.value.replace(/\D+/g, "")'/>太牛了,感谢分享,正好用到 HTML<asp:TextBox ID="TextBox36" runat="server" onkeypress = "clearNoNum(this)" oninput= "clearNoNum(this)" onpropertychange="clearNoNum(this)" sonblur = "clearNoNum(this)" style="margin-bottom: 0px;" Width="117px"></asp:TextBox>JS<script language="JavaScript" type="text/javascript">function clearNoNum(obj){ obj.value = obj.value.replace(/[^\d.]/g,""); //清除“数字”和“.”以外的字符 obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字而不是. obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的. obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");}</script> 不兼容 火狐哦, 加上后,什么都不能输入了,ie、google试过能兼容。 jsp中插入flash按钮添加链接没反应 在extjs中,panel中。从后台读取数据 今天要交作业,增加订单的题不会做,请各位大侠指点迷津!!! 各位高手帮忙看看,我又遇到难题了! 求处理表格列宽、行高的 js 代码。在线等 新浪首页娱乐和音乐两个标签栏位如何做的 过中国自己的节日,我们不过“圣诞”节 老问题了,看了搜索的帖子仍然解决不了.求救!!!!!!!! function怎么可以这么定义的? 求解几个问题 googleMap上绘制轨迹图的问题 js $(#form).submit失灵,求原因
<script type="text/javascript">
function getEvent() {
if (document.all) {
return window.event; //for ie
}
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
}
function doit(){
var ev = getEvent();
if(ev.keyCode < 48 || ev.keyCode > 57) return false;
}
</script>
<input type="text" id="txt" onkeydown="return doit()">
onblur = 'this.value = this.value.replace(/\D+/g, "")'
这个只能适用于IE 但FF不行
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
</body>
</html>
试试这个
可以加样式禁用输入法(chrome不会起作用)ime-mode:disabled;
{
if (textBox3.SelectionStart == 0)
{
if (e.KeyChar.CompareTo( '0 ') == 0 || e.KeyChar.CompareTo( '0 ') < 0 || e.KeyChar.CompareTo( '9 ') > 0)
{
e.Handled = true;
}
}
else
{
if (e.KeyChar.CompareTo( '0 ') < 0 || e.KeyChar.CompareTo( '9 ') > 0)
{
if (e.KeyChar != '\b ')
e.Handled = true;
}
}
}
onkeypress = 'return /^\d$/.test(String.fromCharCode(event.keyCode))'
oninput= 'this.value = this.value.replace(/\D+/g, "")'
onpropertychange='if(!/\D+/.test(this.value)){return;};this.value=this.value.replace(/\D+/g, "")'
onblur = 'this.value = this.value.replace(/\D+/g, "")'/>回复给你了,四事件组合,牛B轰轰的限制输入,至少兼容Firefox、IE、Chrome。
事件兼容<input type="text"
onkeypress = 'return /^\d$/.test(String.fromCharCode(event.keyCode||event.keycode||event.which))'
oninput= 'this.value = this.value.replace(/\D+/g, "")'
onpropertychange='if(!/\D+/.test(this.value)){return;};this.value=this.value.replace(/\D+/g, "")'
onblur = 'this.value = this.value.replace(/\D+/g, "")'/>
我怎么测得还是出来了,右键贴的这么多人 帮看下我的问题
http://topic.csdn.net/u/20111207/21/3bbfb031-0a42-4ed2-9de7-3ebac6dec751.html?57709
事件兼容<input type="text"
onkeypress = 'return /^\d$/.test(String.fromCharCode(event.keyCode||event.keycode||event.which))'
oninput= 'this.value = this.value.replace(/\D+/g, "")'
onpropertychange='if(!/\D+/.test(this.value)){return;};this.value=this.value.replace(/\D+/g, "")'
onblur = 'this.value = this.value.replace(/\D+/g, "")'/>
太牛了,感谢分享,正好用到
<asp:TextBox ID="TextBox36" runat="server"
onkeypress = "clearNoNum(this)"
oninput= "clearNoNum(this)"
onpropertychange="clearNoNum(this)"
sonblur = "clearNoNum(this)"
style="margin-bottom: 0px;" Width="117px"></asp:TextBox>
JS
<script language="JavaScript" type="text/javascript">
function clearNoNum(obj)
{
obj.value = obj.value.replace(/[^\d.]/g,""); //清除“数字”和“.”以外的字符
obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字而不是.
obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
</script>
不兼容 火狐哦, 加上后,什么都不能输入了,ie、google试过能兼容。