完整代码如下 :
复制代码代码如下:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transisi // 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 文本框提示效果 </iteme>
<type style = "text/css">
*{
margin: 0px; padding: 0px; font-size: 12px;
}
input {
Lebar: 100px; Tinggi: 20px; Border: 1px Solid #CCC;
}
</tyle>
</head>
<body>
<bahasa skrip = "javascript">
Tips fungsi (id, str) {
var l = document.getElementById (id) .offsetleft+120;
var t = document.geteLementById (id) .offsettop;
document.geteLementById ("Tips"). InnerHtml = "提示 :"+str;
document.geteLementById ("Tips"). style.left = l+"px";
document.getElementById ("Tips"). style.top = t+"px";
document.getElementById ("Tips"). style.display = "";
}
fungsi outtips () {
document.geteLementById ("Tips"). style.display = 'none';
}
</script>
<Div id = "Tips" style = "Posisi: Absolute; Border: 1px solid #ccc; padding: 0px 3px; warna:#f00; Tampilan: Tidak Ada; Tinggi: 20px; Line-Height: 20px; latar belakang: #fcfcfc"> </div>
<br />
姓名 : <input type = "text" id = "username" onfocus = "tips ('username', '姓名长度最多 16 个字符')" onblur = "outtips ()" / />
<br />
密码 : <input type = "password" id = "password" onfocus = "Tips ('password', '密码长度必须在 3-18 位之间')" OnBlur = "OutTips ()" />
</body>
</html>