<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" language="javascript">
<!--当文本框的内容为空时,显示鼠标跟随效果-->
function showlianxi(status,ev){
var e= ev||window.event;
var show = document.getElementById('showlianxi');
var obj=e.target||e.srcElement;
if(fun()){
switch(status){
case 'over':
show.style.position='absolute';
if(e.pageX){
show.style.left=e.pageX+20+'px';
show.style.top=e.pageY+'px';
}
else{
show.style.left=e.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft+5;
show.style.top=e.clientY + document.body.scrollTop+ document.documentElement.scrollTop+5;
}
show.style.display='block';
break;
case 'out':
show.style.display='none';
break;
}
} else{
show.style.display='none';
}
}
<!--判断文本框的内容是否为空-->
function fun(){
var temp=document.getElementById("username").value;
if(temp==null||temp==''){
return true;
}else{
return false;
}
}
</script>
</head>
<body>
<input type="text" id="username" οnmοuseοut="showlianxi('out',event)" οnmοusemοve="showlianxi('over',event)" />
<div id="showlianxi" style="display:none">
<a>请填写值</a>
</div>
</body>
</html>