在IE中嘗試創建一個工具提示時會遇到offsetLeft和offsetTop問題,每當我們點擊日曆上的不同事件時,都會創建一個工具提示。下面是代碼,它可以用於firefox,但創建問題爲IE。能告訴我這種情況的解決方案..IE中的OffsetLeft和OffsetTop問題
var ttip = __createElement("div","ttipbox","ttipbox"); //creating div
target = document.getElementById("sDiv"+ndiv); //taking the object of event on click of it tooltip has to display.
var x = target.offsetLeft ;
var y = target.offsetTop - (currObj.childNodes[2].childNodes[0].childNodes[1].scrollTop + ttip.offsetHeight);
ttip.style.top= y+15;
ttip.style.left= x - 80;
ttip.style.zIndex= "2000";
在此先感謝
是什麼問題?它出現在錯誤的位置?或根本沒有? – scunliffe 2009-07-31 11:30:23
PS一般來說,我會將頂/左值設置爲包含'px'後綴的字符串。例如ttip.style.top =(y + 15)+'px'; – scunliffe 2009-07-31 11:31:38