2014-11-27 5 views
-3

정말 혼란 스럽습니다. 이 코드 조각은 컴퓨터의 로컬 서버에 있어야하는 것처럼 작동합니다. 하지만 firefox 디버거에서 중단 점을 설정하면 deck-title 클래스를 클릭 할 때이 함수가 호출되지 않기 때문에 내가 hostgator 서버에 업로드 한 후이 함수는 더 이상 실행되지 않습니다. 그러나 지역적으로 중단 점이 작동하고 함수가 호출됩니다.JQuery .click (function() {})은 로컬에서는 작동하지만 서버에서는 작동하지 않습니다.

// when click the decks, the current deck should change 
$(document).ready(function() { 
    $(".deck-title").click(function() { 
     var deckTitle = $(this).text(); 
     $("#current-deck-span").html(deckTitle); 
     if (deckTitle !== current_deck_global) { 
      var deckID = getDeckIDFromTitle(deckTitle); 
      updateDisplayingDeck(current_userID, deckID); 
     } 
     current_deck_global = $(this).text(); 
    }); 
}); 

click(function()에 어떤 아이디어?

<head> 
    <title></title> 
    <meta charset="utf-8"></meta> 
    <link href="./css/home.css" type="text/css" rel="stylesheet"></link> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
</head> 

나는 다른 전에 먼저 JQuery와 스크립트를로드 오전 : 내 말은은, 다른 모든 jQuery 코드는 여기에

내 웹 페이지에서 <head>입니다 ...이 일을 제외하고는 Hostgator를 서버에 괜찮 았는데 스크립트. 그래서 $(document).ready(function()) 작동합니다 (I는 또한 문서가 준비하고, 참으로 테두리 표시 후 모든 CSS 요소를 테두리를 제공하여 확인.

난 정말 어떤 도움을 주셔서 감사합니다! 감사합니다!

+1

당신의 사이트에 링크를 제공 할 수 있습니까? – demonofthemist

+0

당신은'deck-title'을 동적으로 생성하고 있습니까 –

+8

왜 jquery 라이브러리를 두 번로드합니까? – Mivaweb

답변

1

당신의 핸들러가 실행되는 것 같다 . 너무 일찍 이벤트 위임 사용해보십시오 :. 당신의 CSS는 당신은 당신의 HREF 문자열 앞에 ./를 가지고 있기 때문에 첫 번째 링크 태그에서 제대로로드지고 있지 않은 경우 내가 궁금하네요

$(document).on("click", ".deck-title", function() { 
    //..... 
}); 
+0

예! 이것이 해결책입니다! – zkytony

0

을 나는

을 것을 제거하려고 할 것이다
1

우선 sp ecifiy DocType을 VDesign이 주석 처리 한 다음 스크립트 블록에이 코드를 넣어 wheather jQuery 라이브러리가로드되었는지 확인하십시오.

<script type="text/javascript"> 
if (typeof(jQuery) == 'undefined') { 
    var jq = document.createElement("script"); 
    jq.type = "text/javascript"; 
    jq.src = "http://code.jquery.com/jquery-1.9.0.js"; 
    document.getElementsByTagName('head')[0].appendChild(jq); 
} 
</script> 

로드 한 후에는 스크립트를 그대로 추가 할 수 있습니다.

// when click the decks, the current deck should change 
$(document).ready(function() { 
    $(".deck-title").click(function() { 
     var deckTitle = $(this).text(); 
     $("#current-deck-span").html(deckTitle); 
     if (deckTitle !== current_deck_global) { 
      var deckID = getDeckIDFromTitle(deckTitle); 
      updateDisplayingDeck(current_userID, deckID); 
     } 
     current_deck_global = $(this).text(); 
    }); 
}); 

희망이 있습니다.

관련 문제