<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>lik-input-number</title> </head> <body> <input type="text" class="lik_input_number" style="color:#ccc" value="请输入数字" onfocus="fn_focus(this);" onblur="fn_blur(this);" onkeydown="value = this.value.replace(/[^0-9.]/g, '');" onkeyup="value = this.value.replace(/[^0-9.]/g, '');"> </body> <script src="jquery-1.8.1.min.js"></script> <script> // 输入框模拟placeholder function fn_focus(ele) { if (ele.value == ele.defaultValue) { ele.style = "color:#333"; ele.value = ''; } else { ele.style = "color:#333"; } } function fn_blur(ele) { var reg = /^[s]*$/; if (reg.test(ele.value) || ele.value == ele.defaultValue) { ele.style = "color:#ccc"; ele.value = ele.defaultValue; } else { ele.style = "color:#333"; } } </script> </html>