img里哪有title
if(event.srcElement.title && (event.srcElement.title!='' ¦ ¦ (event.srcElement.title=='' && tempalt!=''))){ 
这个图片就过不去var flag = false ;
if(event.srcElement.title && (event.srcElement.title!=''|| (event.srcElement.title=='' && tempalt!=''))){ 
flag=true;
}
if(event.srcElement.alt && (event.srcElement.alt!=''|| (event.srcElement.alt=='' && alt!=''))){ 
flag=true;
}
if (flag){ 
altlayer.style.left=event.x; 
altlayer.style.top=event.y+20; 
altlayer.style.display=''; 
。。试试吧

解决方案 »

  1.   

    看了一下代码,如果要达到链接的效果,需要指定 img 的 title 而不是 alt
    当然,两个属性同时出现也没问题,但 title 必须出现比如 
    <img src=1.gif title="哈哈" altbg='#3980f4' altcolor='#ffffff' altborder='#ffffff'/>
    <img src=1.gif title='灌篮高手经理在线' alt="aaaa"  altbg='#3980f4' altcolor='#ffffff' altborder='#ffffff' />
      

  2.   

    简单整了一个:
    <html>
    <head>
    <meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
    <title>自定义Title</title>
    <script type="text/javascript">
    var easyTitle = function(dModule){
        this.parent = dModule;
        this.init();
    }easyTitle.prototype = {
        getElementsByTitle:function(dModule){
            if(!dModule) return null;
            var dMC = dModule.childNodes,aDC = [],at = null;
            for(var i=0,l=dMC.length;i<l;i++){
                at = (dMC[i].getAttribute)?dMC[i].getAttribute("title"):null;
                if(!!at) aDC.push(dMC[i]);
            }
            return aDC.slice(0);
        },
        addEventListen:function(d,e,f,c){
            if(d&&f){
                if(document.attachEvent){
                   for(var i=0,l=d.length;i<l;i++) d[i].attachEvent('on'+e,f);
                }else{
                   for(var i=0,l=d.length;i<l;i++) d[i].addEventListener(e,f,c);
                }
            }
        },
        showTitle:function(e){
            var e = e||window.event,dObj = e.srcElement||e.target;
            var x = e.clientX,y = e.clientY;
            var sTitle = dObj.getAttribute('title'),sCss = dObj.getAttribute('titlestyle');
            var dTitle = document.getElementById('easyTitleShow');
            if(sTitle){
                dTitle.innerHTML = sTitle;
                sCss += ';position:absolute';
                sCss += ';left:'+(x-2)+'px';
                sCss += ';top:'+(y+19)+'px';
                sCss += ';display:;';
                dTitle.style.cssText = sCss;
            }
        },
        hideTitle:function(){
            var dTitle = document.getElementById('easyTitleShow');
            dTitle.style.display = 'none';
        },
        init:function(){
            var aTitle = this.getElementsByTitle(this.parent);
            if(aTitle){
                var dTitle = document.createElement('DIV');
                dTitle.style.display = 'none';
                dTitle.setAttribute('id','easyTitleShow');
                document.body.appendChild(dTitle);
                this.addEventListen(aTitle,'mouseover',this.showTitle,false);
                this.addEventListen(aTitle,'mousemove',this.showTitle,false);
                this.addEventListen(aTitle,'mouseout',this.hideTitle,false);
            }
        }
    }</script>
    </head>
    <body><img src='http://www.csdn.net/Images/logo_csdn.gif' title='CSDN床上等你' titlestyle='background:#eee;color:#000;border:1px solid #999;' /><a href='http://www.csdn.net/' title='深入浅出CSDN' titlestyle='background:#000;color:#f00;border:1px solid #0f0;'>深入浅出CSDN</a><script type="text/javascript">
    var et = new easyTitle(document.body);
    </script>
    </body>
    </html>
      

  3.   

    <html> 
    <head> 
    <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> 
    <title>网页特效|Linkweb.cn/Js|---自定义Title </title> 
    </head> 
    <body> <a href='' title='鼠标跟随' altbg='#3980f4' altcolor='#ffffff' altborder='#ffffff'>大字体 </a> <br> <br> 
    <img src=1.gif alt='灌篮高手经理在线' title="12345"  altbg='#3980f4' altcolor='#ffffff' altborder='#ffffff' /> 
    <div style='display:none;height:30px;padding:10px 10px 10px 10px;FILTER: Alpha(Opacity=80);border:1px solid #000000;background-color:#FFFFCC;font-size:12px;position:absolute;' id=altlayer> </div> 
    <script type='text/javascript'> document.body.onmousemove=quickalt; 
    document.body.onmouseover=getalt; 
    document.body.onmouseout=restorealt; 
    var tempalt=''; function getalt(){ 
    if(event.srcElement.title && (event.srcElement.title!='' || (event.srcElement.title=='' && tempalt!=''))){ 
    altlayer.style.left=event.x; 
    altlayer.style.top=event.y+20; 
    altlayer.style.display=''; 
    tempalt=event.srcElement.title; 
    tempbg=event.srcElement.altbg; 
    tempcolor=event.srcElement.altcolor; 
    tempborder=event.srcElement.altborder; 
    event.srcElement.title=''; 
    altlayer.innerHTML=tempalt; 
    if (typeof(tempbg)!="undefined"){altlayer.style.background=tempbg}else{altlayer.style.background="infobackground"} 
    if (typeof(tempcolor)!="undefined"){altlayer.style.color=tempcolor}else{altlayer.style.color=tempcolor="infotext"} 
    if (typeof(tempborder)!="undefined"){altlayer.style.border='1px solid '+tempborder;}else{altlayer.style.border='1px solid #000000';} 


    function quickalt(){ 
    if(altlayer.style.display==''){ 
    altlayer.style.left=event.x; 
    altlayer.style.top=event.y+10; 


    function restorealt(){ 
    event.srcElement.title=tempalt; 
    tempalt=''; 
    altlayer.style.display='none'; 
    } </script> </body> 
    </html> 应该能解决了。