js的一些应用技巧

1.保持layer在最前面,而不被Iframe、Object所覆盖
 在Layer中再插Iframe 或 Object 设z-Index值
 <div z-Index:2><object xxx></object> #前面
 <div z-Index:1><object xxx></object> #后面
 <div id="Layer2" style="position:absolute; top:40;400px;
 height:95px;z-index:2"> height=100% width=100%>
 <iframe width=0 height=0></iframe>
 </div>
 <div id="Layer1" style="position:absolute; top:50;200px;
 height:115px;z-index:1">
 <iframe height=100% width=100%></iframe> 字串6
 </div>

2. 取得控件的绝对位置
//javascript
<script language="javascript">
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"/nleft="+l);
}
</script>

   GetNowObjectPosition: function(a){
        this.obj = a;
        var b = a.offsetLeft;
        var c = a.offsetTop;
        var d = a.offsetParent;
        while (d != null) {
            if (d.tagName != "BODY") {
                b += d.offsetLeft;
                c += d.offsetTop;
                d = d.offsetParent
            }
            else {
                b += document.body.offsetLeft || 0;
                c += document.body.offsetTop || 0;
                break
            }
        }
        return {
            X: b,
            Y: c
        }
    },

           var c = MyUtility.GetNowObjectPosition(objPlaceID);
            newMask.style.top = c.Y + "px";
            newMask.style.left = c.X + "px";

 3.脚本永不出错
<SCRIPT LANGUAGE="javascript">
<!-- Hide
function killErrors() {
return true;
}
window.onerror = killErrors;
// -->
</SCRIPT>


 

原文地址:https://www.cnblogs.com/aaa6818162/p/1597177.html