At work, you always encounter a lot of text boxes that prohibit the input of non-numeric characters, such as mobile phone number and zip code.
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<link rel= "stylesheet" href= "Style.css" >
<script src= "Http://libs.baidu.com/jquery/1.9.0/jquery.js" ></script>
<body>
<input type= "text" id= "phone" value= "0000" >
</body>
<script type= "Text/javascript" >
JQuery (document). Ready (function ($) {
Stuff to did as soon as the DOM is ready;
var phone=$ (' #phone ');
$ (phone). On (' click ', function () {
Phone.val (");
})
$ (phone). On (' KeyUp ', function (evt) {
var phoneval=phone.val ();
Phoneval=phoneval.replace ('/[^\d]+/g ', '); Replace a non-numeric character with a space
Phoneval=parseint (phoneval,10);
if (isNaN (Phoneval)) {
Phoneval = ';
}
This.value=phoneval;
})
});
</script>