日期:2014-05-18  浏览次数:20558 次

如何用js限制文本框的输入,在0~100之间 ,>100 则变为100
rt

------解决方案--------------------
if(ParesInt(document.getElementById( "txt ").value) > 100)
{
document.getElementById( "txt ").value = 100;
}
------解决方案--------------------
用AjaxPro技术在CS页面里做一个判断,再返回一个一值,再判断这个值
如果这个值大于100,就document.getElementById( '文本框名称 ').innerText= "100 ";
------解决方案--------------------

允許0 <=x <=100 x為整數或小數

txt.Attributes.Add( "onPropertyChange ", " if(isNaN(this.value.replace( '. ', ' ')) || (this.value > 100) || (this.value < 0)){this.value = 0;} ");
------解决方案--------------------
txt.Attributes.Add( "onPropertyChange ", " if(isNaN(this.value.replace( '. ', ' ')) || (this.value > 100) || (this.value < 0)){this.value = 100;} ");

------解决方案--------------------
顶LS
------解决方案--------------------
用RangeValidator验证不是很好?
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:TextBox ID= "txtNum " runat= "server "> </asp:TextBox>
<asp:RangeValidator ID= "RangeValidator1 " runat= "server " ControlToValidate= "txtNum "
Display= "Dynamic " ErrorMessage= "请输入0-100的整数 " MaximumValue= "100 " MinimumValue= "0 "
Type= "Integer "> </asp:RangeValidator> <br />
<asp:Button ID= "Button1 " runat= "server " Text= "Button " />

</div>
</form>
</body>
</html>
------解决方案--------------------
先判读输入值必须为正数
再判断是否大于100
------解决方案--------------------
很简单啊
------解决方案--------------------
先判断是否为数字
function setRange()
{
var v=document.all( 'tbMe ').value;
if (! isNaN(v))
{
//换成整数
var n=parseInt(v);
if n <0
document.all().value= '0 '
else if n> 100
document.all().value= '100 ';
}
}

------解决方案--------------------
上面括号里是id名 忘写了呵呵
------解决方案--------------------
先判断是否为数字
function setRange()
{
var v=document.all( 'tbMe ').value;
if (! isNaN(v))
{
//换成整数
var n=parseInt(v);
if n <0
document.all().value= '0 '
else if n> 100
document.all().value= '100 ';
}
}