2011-05-06 2 views
2

요소에서 attr 제목을 제거하려고하면 요소를 가리키는 두 번째 요소가 삭제됩니다.즉, removeAttr title 문제가 발생했습니다.

이 문제는 Internet Explorer에서만 발생합니다. 당신은 단지 mouseovertitle 속성을 제거하기 때문에

$('span').live({"mouseover": function(){ 
    clearTimeout($(this).data('timeoutId')); 
    var title = $(this).attr('title'); 
    $(this).removeAttr("title"); 
    if($(this).children('.tip-hover').length > 0){ 
     if($(this).children('.tip-hover').is(':visible') == false){ 
      $(document).find('.tip-hover').hide(); 
      $(this).children('.tip-hover').fadeIn(100); 
     }else{ 
      $(document).find('.tip-hover').hide(); 
      $(this).children('.tip-hover').show(); 
     } 
    }else{ 

     if(title != false){ 
      var height = $(this).css('line-height') + 2; 
      $(this).prepend('<div class="tip-hover"><div class="tip-top"></div><div class="tip-hover-wrap"><div class="tip-hover-inner">' + title + '</div></div></div>'); 
      $(this).children('.tip-hover').css("margin-top", height + "px"); 
      var width = $(this).width()/2; 
      $(this).children('.tip-hover').css("padding-left",width+"px"); 
     } 
    } 

}, 
    "mouseout": function() { 
     var someelement = this; 
     var timeoutId = setTimeout(function(){ $(someelement).find(".tip-hover").fadeOut("slow");}, 350); 
     $(someelement).data('timeoutId', timeoutId); 
    } 
}); 
+2

jQuery를 101 : 변수에 $ (이)에 대한 참조를 저장 당신은 필요가 없습니다 그것을 찾는 것은 $() 비싸다. – epascarello

+0

또한 뭔가가 부울 false 값으로 설정되지 않으면'if (title! = false)'가 false가 될 수 없습니다. 속성을 삭제해도 false가 생성되지 않습니다. 그 팁을 – epascarello

+0

고맙습니다! 바로 바꿨어! 내가 어떻게 그럴거야? 제목이 존재하는지 확인하십시오! –

답변

4

title 처음 표시되는 이유는 다음과 같습니다

여기에 코드입니다. 그때가 이미 너무 늦었습니다!

문서를로드하자마자 사용자 정의 data-* 속성에 백업을 저장하면 이벤트 처리기 외부에서 제목 속성을 제거하는 것이 좋습니다.

$(function() { 
    $('span').each(function() { 
    var $this = $(this); 
    $this 
     .data('title', $this.attr('title')) 
     .removeAttr('title'); 
    }); 
}); 

그런 다음, 코드, 대신 ...에

에게
var title = $(this).attr('title'); 

는 사용 :

var title = $(this).data('title'); 
+0

감사합니다. m8. 이것은 문제를 해결했습니다! –

+0

내가 데이터를 저장하는 동안 내가 문서 하중에 div를 앞에 추가하면 더 좋을까요? –

관련 문제