Text box can only enter numbers. Implementation method of compatible IE Firefox
- 2021-07-01 06:14:33
- OfStack
The text box can only enter numbers (compatible with IE Firefox)
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Untitled document </title>
<script language="javascript" type="text/javascript">
// Note: Firefox uses event When,
function inputNum(evt){
// Firefox usage evt.which Gets the keyboard key values, IE Use window.event.keyCode Get keyboard key values
var ev = evt.which?evt.which:window.event.keyCode;
if(ev>=48&&ev<=57){
return true;
}else{
return false;
}
}
</script>
</head>
<body>
<input type="text" onKeyPress="return inputNum(event);" >
</body>
</html>