The complete code is as follows:
Copy codeThe Code is as follows:
<! 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" xml: lang = "en" lang = "en">
<Head>
<Title> html text box prompt effect </title>
<Style type = "text/css">
*{
Margin: 0px; padding: 0px; font-size: 12px;
}
Input {
Width: 100px; height: 20px; border: 1px solid # ccc;
}
</Style>
</Head>
<Body>
<Script language = "javascript">
Function tips (id, str ){
Var l = document. getElementById (id). offsetLeft + 120;
Var t = document. getElementById (id). offsetTop;
Document. getElementById ("tips"). innerHTML = "prompt:" + str;
Document. getElementById ("tips"). style. left = l + "px ";
Document. getElementById ("tips"). style. top = t + "px ";
Document. getElementById ("tips"). style. display = "";
}
Function outtips (){
Document. getElementById ("tips"). style. display = 'none ';
}
</Script>
<Div id = "tips" style = "position: absolute; border: 1px solid # ccc; padding: 0px 3px; color: # f00; display: none; height: 20px; line-height: 20px; background: # fcfcfc "> </div>
<Br/>
Name: <input type = "text" id = "username" onfocus = "tips ('username', 'name can contain up to 16 characters')" onblur = "outtips () "/>
<Br/>
Password: <input type = "password" id = "password" onfocus = "tips ('Password', 'password must be 3-18 characters in length ')" onblur = "outtips () "/>
</Body>
</Html>