2012-11-28 27 views
-1

在我正在處理的網站中添加幻燈片後,一些使用Jquery的Web組件停止工作。然而,新添加的也使用JQuery的幻燈片將按預期工作。簡單的JQuery在某些領域工作,而不是在其他領域工作

經過一番調試之後,我發現了JQuery的工作內容,以及下面的代碼中沒有的內容。我在我的代碼中添加了一條評論來表明這一點。

我正在導入我的jQuery庫中的標題,下面的代碼是關閉<body>標記之前的最後一個代碼。

<!--SLIDESHOW-->  
    $(document).ready(function() { 
     var options = {}; 

     if (document.location.search) { 
      var array = document.location.search.split('='); 
      var param = array[0].replace('?', ''); 
      var value = array[1]; 

      if (param == 'animation') { 
       options.animation = value; 
      } 
      else if (param == 'type_navigation') { 
       if (value == 'dots_preview') { 
        $('.border_box').css({'marginBottom': '40px'}); 
        options['dots'] = true; 
        options['preview'] = true; 
       } 
       else { 
        options[value] = true; 
        if (value == 'dots') $('.border_box').css({'marginBottom': '40px'}); 
       } 
      } 
     } 

     $('.box_skitter_large').skitter(options); 

     // Highlight 
     $('pre.code').highlight({source:1, zebra:1, indent:'space', list:'ol'}); 

      //**** everything above works, everything below this point does not! ****/ 
     $(".expandButton").click(function(ev){ 
      $(ev.target).closest(".company-container").find(".expand").css("height", "140px"); 
      $(ev.target).closest(".company-container").find(".expand").toggle("fast"); 
     });   
     $(".emailLink, .email-popup").click(function(e){ 
      e.stopPropagation(); 
      $(e.target).closest(".company-container").find(".expand").css("height", "140px"); 
      $(e.target).closest(".company-container").find(".email-popup").show("fast"); 
      $(e.target).closest(".company-container").find(".phone-popup").hide(); 
      $(e.target).closest(".company-container").find(".address-popup").hide(); 
     }); 
     $(".addressLink, .address-popup").click(function(e){ 
      e.stopPropagation(); 
      $(e.target).closest(".company-container").find(".expand").css("height", "550px"); 
      $(e.target).closest(".company-container").find(".address-popup").show("fast"); 
      var address = $(e.target).closest(".company-container").find(".address").html(); //get address text 
      if(!($(e.target).closest(".company-container").find(".map").length)){ //check if it was loaded 
       $(e.target).closest(".company-container").find(".address-popup").html('<iframe class="map" style="margin-top:45px;" width="575" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q='+ address +' &amp;aq=&amp;ie=UTF8&amp;hq=&amp;hnear='+address+'&amp;t=m&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>'); 
      } 
      $(e.target).closest(".company-container").find(".email-popup").hide(); 
      $(e.target).closest(".company-container").find(".phone-popup").hide(); 
     }); 
     $(".phoneLink, .phone-popup").click(function(e){ 
      e.stopPropagation(); 
      $(e.target).closest(".company-container").find(".expand").css("height", "140px"); 
      $(e.target).closest(".company-container").find(".phone-popup").show("fast"); 
      $(e.target).closest(".company-container").find(".email-popup").hide(); 
      $(e.target).closest(".company-container").find(".address-popup").hide(); 
     }); 
     $(document).click(function(e) { 
      if (!(e.target.class === "email-popup" || e.target.class === "phone-popup")) { 
       $(".email-popup, .phone-popup, .address-popup").hide("fast");     
      } 
      $(".expand").css("height","140px"); 
     });  
     $(".tagKeyword").hover(function(){ 
      $(this).css("background-color","#fff"); 
      $(this).css("color","blue"); 
      $(this).css("box-shadow","none"); 
     }); 
     $(".tagKeyword").mouseleave(function(){ 
      $(this).css("background-color","#eee"); 
      $(this).css("color","#556"); 
      $(this).css("box-shadow","1px 1px 2px #ccc"); 
     }); 
     $(".search-container").hover(function(){ 
      $(".search-container").css("background","url(./images/menu/menu-middle.png)"); 
     }); 
     $(".searchfield").Watermark("search"); 
    }); 
+0

我恨聽起來很煩,但利用的console.log,三重檢查那裏它打破。然後只需在該區域內進行分區,並確定該代碼是否可以自行工作。讓我們知道你發現了什麼。 – zeMinimalist

回答

0

你能試試嗎?

$(".expandButton").click(function() { 
    $(this).closest(".company-container").find(".expand").css("height", "140px"); 
    $(this).closest(".company-container").find(".expand").toggle("fast"); 
}); 

這可能不是在所有幫助,但我沒有看到需要ev這裏改用this

+0

感謝您的回覆。給了一個嘗試,它沒有幫助。我一直在使用ev數月。我不明白爲什麼會導致問題。雖然我很欣賞你的意見。 – AnchovyLegend

0

可能是你需要仔細檢查EV變量:

ev = ev || window.event