一段浮动层显示帮助信息的JS及IETESTER的一个错误解决

最近工作写了个帮助提示的东西,效果图:

比较简单,因为做的uchome的二次开发,所以ajax用的是uchome的函数,其他朋友要用换成jQuery或者其他的方式就可以了,代码如下:

//显示帮助信息 帮助ID,呈现控件,显示级别:本类同级1;父类同级2,模式:1.下方显示;2.右上漂浮,显示时间:0不限制,背景色,边框色,宽,高
function help_show(id,obj,op,mode,time,bg,bd,width,height){
//参数获取
var pObj = obj.parentNode; //控件父类
width = width==null?’150px’:width;
height = height==null?’60′:height;
var is_bd = bd==null?false:true;
bd = bd==’def’?'#EFF5F8′:bd;
var is_bg = bg==null?false:true;
bg = bg==’def’?'#FFF16A’:bd;
//创建层
var showDiv = document.createElement(‘div’);
showDiv.setAttribute(‘id’,'help_show_’+id);
//组织层样式
var style = ‘width:’+width+’;height:’+height+’;padding:5px;font-size:11px;color:#5F5E5C;’
if(is_bd)
style+=’border:1px solid ‘+bd+’;’
if(is_bg)
style+=’background-color:’+bg+’;';
if(mode==2) {
style+=”position:absolute;z-index:10002;”; //是否浮动

var current = obj.parentNode;
var actualLeft = obj.offsetLeft;
var actualTop = 0;
while (current !== null){

      actualLeft += current.offsetLeft;
      actualTop += current.offsetTop;
      if(current.tagName==’BODY’)
      current = null;
      else
      current = current.parentNode;
    }
    if(navigator.userAgent.indexOf(“MSIE”)>0)
    style+=”left:”+(actualLeft+obj.offsetWidth+5)+”px;top:”+(actualTop-obj.offsetHeight+5)+”px;”;
    else if(navigator.userAgent.indexOf(“Firefox”)>0)
style+=”left:”+(obj.offsetLeft+obj.offsetWidth+5)+”px;top:”+(obj.offsetTop-obj.offsetHeight+5)+”px;”;
}

//showDiv.setAttribute(’style’,style);
showDiv.style.cssText = style;

var aj = new Ajax();
aj.get(‘/home/help.php?acAjacShow=1&id=’+id,function(s,x){
//alert(s);
showDiv.innerHTML = evalscript(x['XMLHttpRequest']['responseText']);//s
//alert(x['XMLHttpRequest']['responseText']);
if(showDiv.innerHTML!=”"){
//显示链接
if(showDiv.innerHTML.length)
showDiv.innerHTML += “…<br/><a href=’/news/?action-viewnews-itemid-”+id+”‘ target=’_blank’><b>查看详细</b></a>”;
if(op==1)
pObj.appendChild(showDiv);
else
document.documentElement.childNodes[document.documentElement.childNodes.length-1].appendChild(showDiv);//pObj.parentNode.insertBefore(showDiv,pObj.nextSibling);

if(time!=null&&time!=0)
setTimeout(“document.getElementById(‘help_show_”+id+”‘).parentNode.removeChild(document.getElementById(‘help_show_”+id+”‘));”,time);
}
});
}

另外发现个ietester的问题,打开ietester建立一个ie6的tab,输入网址等上2、3秒报错,如下图:

呵呵,解决方法很简单,先用ie7或者ie8的tab打开页面,然后在用ie6的tab就没问题了!

珍惜劳动成果,虽说内容不多,可是也是一个一个字打上的,转载请注明!!关注爱拼可乐吧

你可能感兴趣的:(test)