`
linleizi
  • 浏览: 227569 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

显示不下弹出DIV辅助显示

 
阅读更多
// js方法
function txtMouseOver(obj) {
 try {
		var txtRange = obj.createTextRange();
		var strValue = obj.value;
		obj.value = "";
		var txtWidth = obj.scrollWidth;
		obj.value = strValue;
		var fontWidth = txtRange.boundingWidth;
		if (fontWidth <= txtWidth) {
			return;
		}
		var strHTML = "";
	    strHTML += "<table border=0>";
	    strHTML += "<tr>";
	    strHTML += "  <td  class = 'msg'><div align='center'>" + strValue + "</div></td>";
	  	strHTML += "</tr>";
		strHTML += "</table>";
		
		oRect = obj.getBoundingClientRect(); 
		
		document.all["msgBox"].innerHTML = strHTML;
		if (document.body.clientWidth < parseInt(oRect.left) + parseInt(txtWidth) + 2 + parseInt(fontWidth)) {
			document.all["msgBox"].style.posLeft = document.body.scrollLeft + oRect.left - 17 - fontWidth;
		} else {
			document.all["msgBox"].style.posLeft = document.body.scrollLeft + oRect.left + txtWidth + 2;
		}
		document.all["msgBox"].style.posTop = document.body.scrollTop + oRect.top - 5;
		document.all["msgBox"].style.filter="alpha(opacity=100)";
	} catch(E) {
	}
}

function txtMouseOut(obj) {
	try {
		document.all["msgBox"].innerHTML = "";
	} catch(E) {
	}
}

// html页面
<input style="width:290px" onMouseOver="txtMouseOver(this)" onMouseOut="txtMouseOut(this)" type="text" class="" readonly value="<%=test%>">
<div id="msgBox" style="position: absolute; left: 0px; top: 0px;"></div>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics