<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>检测输入状态</title> </head> <body> <p style="display:none">正在输入</p> <input type="text"> </body> <script> var timer=null; function $(el){ return document.querySelector(el) } $("input").onkeyup=function(e){ if(e.keyCode==8){ $("p").style.display="none"; } else{ clearInterval(timer); $("p").style.display="block"; setInterval(hide,5000); } } function hide(){ $("p").style.display="none"; } </script> </html>