用DIV模拟
onmouseover onmouseout触发显示或消失
onmouseover onmouseout触发显示或消失
解决方案 »
- 鼠标离开下拉菜单隐藏问题
- 怎样去掉字符串中的指定元素?
- java和iframe的问题 在线等!求解答
- 各位大大进来看看
- javascrpt动画时gif图片会卡的问题,怎么解决?谁碰到过?
- javascript 数组中的数据有逗号 ,怎样还能正确取得各个数组中的元素!
- 页面中,标签text的脚标,比如name="text1",name="text2",...,name="text100",如何给脚标做循环呢?
- 读取xml页面上某些数据显示在php页面中的js
- 简单问题——怎样在javaScript中把变量值打印出来?
- 怎样判断某个控件存在,以作出下步决定
- 可以利用javascript 查看網頁的源代碼嗎?
- 求一段代码 ,在线等,急!!!!
<html>
<head>
<script>
window.onload = function(){ var oText = document.getElementById('text1');
var oDiv = document.getElementById('divTip1');
oText.onmouseover = function(oEvent){
if(oEvent == null || oEvent == ""){oEvent = window.event;}
oDiv.style.backgroundColor = 'blue';
oDiv.style.visibility = "visible";
oDiv.style.left = oEvent.clientX + 5;
oDiv.style.top = oEvent.clientY + 5;
}
oText.onmouseout = function(){
var oDiv = document.getElementById('divTip1');
oDiv.style.visibility = "hidden";
}
}
</script>
</head>
<body>
<input type="text" value="onmouseover" id="text1" />
<div id="divTip1" style="visibility:hidden;">提示:onmouseover</div>
</body>
</html>
<head>
<script>
window.onload = function(){ var oText = document.getElementById('text1');
var oDiv = document.getElementById('divTip1');
oText.onmouseover = function(oEvent){
if(oEvent == null || oEvent == ""){oEvent = window.event;}
oDiv.style.backgroundColor = 'blue';
var oValue = oText.value;
oDiv.innerHTML = oValue;
oDiv.style.visibility = "visible";
oDiv.style.left = oEvent.clientX + 5;
oDiv.style.top = oEvent.clientY + 5;
}
oText.onmouseout = function(){
var oDiv = document.getElementById('divTip1');
oDiv.style.visibility = "hidden";
}
}
</script>
</head>
<body>
<input type="text" value="onmouseover" id="text1" />
<div id="divTip1" style="visibility:hidden;"></div>
</body>
</html>
用DIV模式
<script >
function showKccs(){
var kccsdiv=document.createElement("div");
kccsdiv.className="XA-uplist";
kccsdiv.id='kccsdiv';
document.body.appendChild(kccsdiv);
document.getElementById("kccsdiv").style.top=25;
document.getElementById("kccsdiv").style.left=300;
//alert(document.getElementById("kccsdiv").style.top);
document.getElementById("kccsdiv").style.display='';
document.getElementById("kccsdiv").style.position="absolute";
document.getElementById("kccsdiv").innerHTML='';
document.getElementById("kccsdiv").innerHTML="<%=KccsString.getKccsStr(basePath)%>";
document.getElementById("kccsdiv").attachEvent('onmouseleave',closeDiv);
}
var closeDiv=function (){
//alert(document.getElementById("kccsdiv").style.display);
document.getElementById("kccsdiv").style.display='none';
}
</script>
如此创建必须要有id才能取到属性,在设置样式,document.getElementById("kccsdiv").style.position="absolute";这句就可以完成样式的丢失了,
document.getElementById("kccsdiv").style.display='none';
必须注意
IE下可以超出窗口的提示。<!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>
</head>
<body>
<div id="con">
<span sug="长呀呀好长呀长呀好长呀好长呀长呀好长呀长呀好长呀好长呀好长呀ABC好长呀ABC好长呀好99999990好长呀ABC">文字标题文字标题</span>
<br/>
<br/>
<span sug="很长的很长的文字提示很长的很长的文字提示ABC">文字标题文字标题</span>
<br/>
<br/>
<span sug="很长的很长的文字提示很长的很长的文字提示ABC">文字标题文字标题</span>
<br/>
<br/>
<span sug="很长的很长的文字提示很长的很长的文字提示ABC">文字标题文字标题</span>
<br/>
<br/>
</div>
<script>
function sug(con){
var bcon = document.createElement('div');
var par = document.getElementById(con);
var elms = par.childNodes;
par.sug = bcon;
par.appendChild(par.sug);
for (var i = 0; i < elms.length; i++)
if (elms[i].nodeType == 1 && elms[i].getAttribute('sug')) {
elms[i].onmouseover = function(){
vis_sug(this);
}
}
}
function vis_sug(o){
var myPopupDiv = o.parentNode.sug;
var val = o.getAttribute('sug');
var l, t, w, h;
var p = window.createPopup();
var pbody = p.document.body;
with (pbody) {
//General Appearance
style.verticalAlign = 'middle';
style.backgroundColor = 'lightyellow';
style.border = 'solid black 1px';
//Font Settings
style.fontFamily = 'Arial';
style.fontWeight = 500;
style.fontStyle = 'normal';
style.fontSize = '12pt';
style.color = '#004080';
style.whiteSpace = 'nowrap';
}
with (myPopupDiv) {
style.position = 'absolute';
style.visibility = 'hidden';
style.whiteSpace = 'nowrap';
style.fontFamily = pbody.style.fontFamily;
style.fontWeight = pbody.style.fontWeight;
style.fontSize = pbody.style.fontSize;
style.fontStyle = pbody.style.fontStyle;
innerHTML = val;
}
l = o.offsetLeft;
t = o.offsetTop;
h = o.offsetHeight + 1;
w = myPopupDiv.offsetWidth + 4;
pbody.innerText = val;
p.show(l, t, w, h, document.body);
}
window.onload = function(){
sug('con')
}
</script>
</body>
</html>