2014-04-21 5 views
0

저는 매우 새로운 기능입니다. 누군가가 올바른 방향으로 나를 가리킬 수 있습니까?.bind() .live()는 Safari 나 Chrome에서는 작동하지 않지만 Firefox에서는 작동합니다.

파이어 폭스에서 원하는 방식으로 웹 사이트를 운영하고 있지만 Safari 나 Chrome에서 테스트 해보니 작동하지 않습니다. 나중에 더 많은 문제가있을 것이라고 확신하지만 첫 번째 문제는 내 주요 탐색 버튼이 작동하지 않는다는 것입니다. 클릭 핸들러 및 mouseleavemouseenter이 작동하지 않습니다.

이 코드에 문제가 있습니까? 아니면 다른 곳에서 문제가 될 수 있습니까?

function onLoad() { 
    var $list= $('#mainNavList'); 
    showMainMenu(); //make menus appear 
    specifyScrollingElement('#mainNavList'); 
    specifyScrollingElement('#lowerNav'); 
    $list.find('.linkInactive').live('click', onMainNavMenuClick); 
    $('.albumLink').parent().bind('mouseenter',function(){ 
     $(this).css({'background-color': '#fff'}); 
     }); 

    $('.albumLink').parent().bind('mouseleave',function(){ 
      if ($(this).hasClass('current')==false){ 
      $(this).css({'background-color': 'rgba(233,229,194,.9)'}); 
      }; 
    }); 

    $('.textLink').parent().bind('mouseenter',function(){ 
     $(this).css({'background-color': 'rgba(65,65,65,.8)'}); 
     });   
    $('.textLink').parent().bind('mouseleave',function(){ 
     if (portfoliosActive ==false && $(this).children().hasClass('portfolioButton')==true){ 
     $(this).css({'background-color': 'transparent'}); 
      }; 
     if (portfoliosActive ==true && $(this).children().hasClass('homeButton')==true){ 
      $(this).css({'background-color': 'transparent'}); 
      }; 
    }); 
    $list.find('.linkActive').live('click',function(){ 
      var $this = $(this); 
      $this.addClass('linkInactive').removeClass('linkActive');   
      hideThumbs($list); 
    });     
    thumbnailActions('#mainNavList'); 
    thumbnailActions('#lowerNav'); 
    initUpperNavActions(); 
} 
+0

훌륭한 아이디어는 http://jsfiddle.net/ 또는 이와 유사한 샌드 박스 영역에서 샘플을 작동시키는 것입니다. 이렇게하면 무사히 프레임 워크 버전을 변경할 수 있습니다. –

+0

Joe에게 감사 드려요. 그것은 지금 내 머리 위에있다. js fiddle이란 무엇이며 프레임 워크는 무엇입니까? jquery는 프레임 워크인가? – user3558189

+0

예 jQuery는 자바 스크립트로 작성된 프레임 워크입니다. :) jsFiddle : http://www.techrepublic.com/blog/software-engineer/jsfiddle-an-online-playground-for-your-javascript-html-css/#. –

답변

0

나중에 '고통'의 세계를 저장해야하는 '바인딩'과 '라이브'대신 '사용'을 사용하십시오. '에'사용 http://api.jquery.com/live/

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach 
event handlers. Users of older versions of jQuery should use .delegate() 
in preference to .live(). 

그리고 예 : 또한 http://api.jquery.com/bind/

As of jQuery 1.7, the .on() method is the preferred method for attaching 
event handlers to a document. For earlier versions, the .bind() method is 
used for attaching an event handler directly to elements. Handlers are 
attached to the currently selected elements in the jQuery object, so those 
elements must exist at the point the call to .bind() occurs. For more flexible 
event binding, see the discussion of event delegation in .on() or .delegate(). 

과 : 그 방법은

이 추적에 대한 추가 정보를 원하시면 링크를 참조하십시오 .. JQuery와 1.7로 사용되지 않습니다 귀하의 코드는 다음과 같습니다 :

$('.albumLink').parent().on('mouseenter',function(){ 
    $(this).css({'background-color': '#fff'}); 
}); 
+0

도움을 주셔서 대단히 감사드립니다. .bind와 .live를 .on으로 바꾸려고 시도했지만 .delegate도 시도했지만 작동하지 않는 것 같습니다. 내가 파이어 폭스에서 더 이상 작동하지 않고 Safari에서 작동하지 않는다. 이것은 아마도 바보 같은 질문이지만 jquery의 새로운 버전을 사용해야 할 것입니다. 맞습니까? 하지만 그렇게한다면 내가 지금하고있는 일을 망칠 것입니까? 새로운 버전에서와 같이 명령은 더 이상 사용되지 않습니다.하지만 이전 버전을 사용하는 경우에는 사용되지 않는 스크립트가 작동하지 않습니다. 어떻게 Firefox에서 작동하지만 다른 브라우저에서는 작동하지 않습니까? – user3558189

+0

예, 'on'과 'live'를 사용하려면 jquery에 최신 버전이 필요합니다. 1.9 이상을 사용하십시오. 또한 항상 한 버전 만 남기고, 현재 버전을 완성 할 수있는 공간을 제공하십시오. 당신이 그것을 이해했기 때문에 기쁜! –

0

즉, 바인딩되고 지속됩니다. 나는 문제없이 크롬에서 사용한다. 대표는 매개 변수 순서를 전환 : 당신이 이전 jQuery를 사용하는 경우

$(".albumLink").on('click', function() { 
    $(this).css({'background-color': 'rgba(65,65,65,.8)'}); 
}); 

http://api.jquery.com/on/ 당신은 http://api.jquery.com/delegate/

는 ** 주) (대표를 사용해야 할 수도 있습니다. 나중에 JQuery와 (1.7) .delegate() CSTE 연구진은 단지 별칭() 어쨌든

HTH이다에서

0

나는 작업에 얻을 수 또는 위임하지 않았다. 나는 jquery를 사용하는 방법에 대해 아직도 혼란 스럽다고 생각한다.

하지만 문제는 내 클릭과 마우스 센터 및 마우스가 작동하지 않는 것으로 파악했습니다. 코드에서 여분의 "</div>"을 발견했기 때문에 보이지 않는 div가 내 탐색 버튼을 차단하고 있다고 생각합니다. 삭제 한 후에 버튼이 모두 Safari 및 Chrome에서 갑자기 작동합니다. 시간 내 줘서 고마워!

관련 문제