JavaScript鼠标点到文本框时的提示信息

本文介绍了一个简单的HTML页面结合JavaScript实现的输入框提示效果。当用户聚焦于输入框时,会显示相应的输入规范提示,离开输入框时提示消失。该示例展示了如何使用基本的HTML结构配合简单的JavaScript函数来增强用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<!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></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;
alert(document.getElementById(id).offsetTop); alert(document.getElementById(id).clientHeight);
var t=document.getElementById(id).offsetTop+document.getElementById(id).clientHeight+5;
document.getElementById("tips").innerHTML="提示:"+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 />
姓名:<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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值