惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
月光博客
月光博客
博客园 - Franky
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Martin Fowler
Martin Fowler
雷峰网
雷峰网
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - habin

利用KindEditor实现公司通讯录的维护 在winform嵌入外部应用程序 Devexpress RichEditControl 导入word文件后字体变为方正姚体的解决方案 Js下载文件到本地(兼容多浏览器) 解决lhgDialog插件在IE11浏览器的BUG Devexpress ChartControl 柱状图简单例子 解决“远程会话已断开连接,因为访问被拒绝导致许可证存储的创建失败,请使用提升的权限运行远程桌面客户端”问题 MVC项目初次发布到IIS可能会遇到的问题 Android Studio下载及离线升级方法 动态调用WebService 统计某个单词出现次数 不能在 Page 回调中调用 Response.Redirect 解决方法 JQuery TextExt 控件使用 通过ashx获取JSON数据的两种方式 终于解决SQL Server 2008 64位系统无法导入Access/Excel的问题 2012/08/01 Asp.net项目部署ActiveReport jQuery Mobile对话框插件 JS实现日期比较 Apache根目录运行.net网站
替换文本框title提示文本
habin · 2012-08-06 · via 博客园 - habin

input自带的title提示效果很弱,用户不注意根本看不见文本框的提示,自己写了一个自定义消息提示的方法,有可能控件在框架里面,所以加了绝对位置获取的代码,如下:

function tips(id,str){
var obj = eval('document.form1.' + id);

var l=getAbsoluteLeft(obj)+getElementWidth(obj)-250;
var t=getAbsoluteTop(obj)-25;

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';
}

//获取控件左绝对位置 
function getAbsoluteLeft(obj) { 
var oLeft = obj.offsetLeft;
while(obj.offsetParent!=null) { 
var oParent = obj.offsetParent   ; 
oLeft += oParent.offsetLeft ;
obj = oParent ;

return oLeft;

//获取控件上绝对位置 
function getAbsoluteTop(obj) { 
var oTop = obj.offsetTop;
while(obj.offsetParent!=null) { 
var oParent = obj.offsetParent   ; 
oTop += oParent.offsetTop ;
obj = oParent ;

return oTop ;

//获取控件宽度 
function getElementWidth(obj) {  
return obj.offsetWidth; 
}

<form id="form1" name="form1">

<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>

<textarea cols=60 rows=2 id=to name=to autocomplete="off" onmouseover="tips('to','这是提示内容')" onmouseout="outtips()"></textarea>

</form>