<html>
<head>
<title></title>
<script type="text/javascript">
var TextUtil = new Object();
TextUtil.allowChars = function(oTextbox,oEvent)
{
var sAllowChars = oTextbox.getAttribute("allowChars");
var sChar = String.fromCharCode(oEvent.keyCode);
var bAllowChar = sAllowChars.indexOf(sChar) > -1;
return bAllowChar || oEvent.ctrlKey;
}
TextUtil.numbericScroll = function (oTextbox,oEvent)
{
var iValue = oTextbox.value.length ==0 ?0:parseInt(oTextbox.value);
var iMax = parseInt(oTextbox.getAttribute("max"));
var iMin = parseInt(oTextbox.getAttribute("min"));
if((oEvent.keyCode == 38)&&(iValue < iMax))
{
oTextbox.value = iValue+1;
}
else if((oEvent.keyCode == 40)&& (iValue > iMin))
{
oTextbox.value = iValue-1;
}
}
</script>
</head>
<body>
<input type="text" title="可使用上下键调整数字大小(0至99之间)" maxlength="2" size="12" max="99" min="0" allowChars="0123456789"
onkeypress="return TextUtil.allowChars(this,event)"
onkeydown="TextUtil.numbericScroll(this,event)" />
</body>
</html>
<head>
<title></title>
<script type="text/javascript">
var TextUtil = new Object();
TextUtil.allowChars = function(oTextbox,oEvent)
{
var sAllowChars = oTextbox.getAttribute("allowChars");
var sChar = String.fromCharCode(oEvent.keyCode);
var bAllowChar = sAllowChars.indexOf(sChar) > -1;
return bAllowChar || oEvent.ctrlKey;
}
TextUtil.numbericScroll = function (oTextbox,oEvent)
{
var iValue = oTextbox.value.length ==0 ?0:parseInt(oTextbox.value);
var iMax = parseInt(oTextbox.getAttribute("max"));
var iMin = parseInt(oTextbox.getAttribute("min"));
if((oEvent.keyCode == 38)&&(iValue < iMax))
{
oTextbox.value = iValue+1;
}
else if((oEvent.keyCode == 40)&& (iValue > iMin))
{
oTextbox.value = iValue-1;
}
}
</script>
</head>
<body>
<input type="text" title="可使用上下键调整数字大小(0至99之间)" maxlength="2" size="12" max="99" min="0" allowChars="0123456789"
onkeypress="return TextUtil.allowChars(this,event)"
onkeydown="TextUtil.numbericScroll(this,event)" />
</body>
</html>

浙公网安备 33010602011771号