完整代码如下
复制代码代码如下:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // pt" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-bransitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en" lang = "en">
<head>
<title> html 文本框提示效果 </title>
<style type = "text/css">
*{
margem: 0px; preenchimento: 0px; tamanho da fonte: 12px;
}
entrada{
largura: 100px; altura: 20px; borda: 1px sólido #ccc;
}
</style>
</head>
<Body>
<Script Language = "JavaScript">
dicas de função (id, str) {
var L = document.getElementById (ID) .offsetLeft+120;
var t = document.getElementById (ID) .offSettop;
Document.getElementById ("Tips"). Innerhtml = "提示:"+str;
document.getElementById ("dicas"). style.left = l+"px";
document.getElementById ("tips"). style.top = t+"px";
document.getElementById ("Tips"). style.display = "";
}
função outtips () {
document.getElementById ("TIPS"). style.display = 'nenhum';
}
</script>
<div id = "Tips" style = "Posição: Absoluto; borda: 1px Solid #ccc; preenchimento: 0px 3px; cor:#f00; display: nenhum; altura: 20px; altura de linha: 20px; fundo: #fcfcfc"> </div>
<br />
姓名: <entrada de entrada = "text" id = "nome de usuário" onfocus = "tips ('nome de usuário', '姓名长度最多 16 个字符')" onblur = "outtips ()" />
<br />
密码 : <input type = "senha" id = "senha" onfocus = "tips ('senha', '密码长度必须在 3-18 位之间')" onblur = "outtips ()" />
</body>
</html>