Sometimes we need to click on the HTML input box and a prompt will appear next to it. As you enter a character, you will be prompted for how many characters are entered below the input box.
Take a look at the example below.
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "UTF-8"> <title>JS Practice</title> <styletype= "Text/css">Body{background:URL ("img/01.jpg") no-repeat Center; }Div{margin:0 Auto; } </style> </Head> <Scripttype= "Text/javascript">window.onload= function(){ varAinput; varaTd; varAName; varamsg; varCountnum; varCount=document.getElementById ("Count"); Ainput=document.getElementsByTagName ("input"); ATd=document.getElementsByTagName ("TD"); AName=ainput[0]; Amsg=atd[1]; Aname.onfocus= function() {amsg.innerhtml= 'time format:yyyy-mm-dd or YYYYMMDD'; } Aname.onblur= function() {Countnum= This. Value.length; if(Countnum==0) {amsg.innerhtml= "'; } Else if(Countnum>Ten ||Countnum<5) {amsg.innerhtml= '<span style= "color:red" > Please enter 5--10 characters! </span>'; return false; }} Aname.onkeyup= function() {Countnum= This. Value.length; Count.innerhtml=Countnum+'of characters'; if(Countnum==0) {count.innerhtml="'; } } } </Script> <Body> <formMethod= "POST" > <Table> <TR> <TD> <inputtype= "text" > </TD> <TD></TD> </TR> <TR> <TDID= "Count"></TD> </TR> </Table> </form> </Body></HTML>
The JS code inside the instance can also be defined as multiple named methods in the script tag. Then add the event to the Input tab.
JS controls the appearance and concealment of HTML text prompts