2014-08-27 84 views
-3

我有一个问题,当我删除下面的代码,视频播放器弹出式播放器工作,但我的联系表格doesnt。Javascript和jQuery的冲突

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 

我加入的脚本没有冲突,但它仍然现在的工作,这里有我的JS和jQuery码这是在头标记。任何帮助将不胜感激。

<script type="text/javascript" src="lib/jquery-1.8.2.min.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 

<script type="text/javascript"> 
    var j = jQuery.noConflict(); 
</script> 

<!-- Add fancyBox main JS and CSS files --> 
<script type="text/javascript" src="source/jquery.fancybox.js?v=2.1.3"></script> 
<link rel="stylesheet" type="text/css" href="source/jquery.fancybox.css?v=2.1.2" media="screen" /> 

<script src="http://jwpsrv.com/library/WDP87vS0EeKnIhIxOUCPzg.js"></script> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     /* 
     * Simple image gallery. Uses default settings 
     */ 

     $('.fancybox').fancybox(); 

     /* 
     * Different effects 
     */ 

     // Change title type, overlay closing speed 
     $(".fancybox-effects-a").fancybox({ 
      helpers: { 
       title : { 
        type : 'outside' 
       }, 
       overlay : { 
        speedOut : 0 
       } 
      } 
     }); 

     // Disable opening and closing animations, change title type 
     $(".fancybox-effects-b").fancybox({ 
      openEffect : 'none', 
      closeEffect : 'none', 

      helpers : { 
       title : { 
        type : 'over' 
       } 
      } 
     }); 

     // Set custom style, close if clicked, change title type and overlay color 
     $(".fancybox-effects-c").fancybox({ 
      wrapCSS : 'fancybox-custom', 
      closeClick : true, 

      openEffect : 'none', 

      helpers : { 
       title : { 
        type : 'inside' 
       }, 
       overlay : { 
        css : { 
         'background' : 'rgba(238,238,238,0.85)' 
        } 
       } 
      } 
     }); 

     // Remove padding, set opening and closing animations, close if clicked and disable overlay 
     $(".fancybox-effects-d").fancybox({ 
      padding: 0, 

      openEffect : 'elastic', 
      openSpeed : 150, 

      closeEffect : 'elastic', 
      closeSpeed : 150, 

      closeClick : true, 

      helpers : { 
       overlay : null 
      } 
     }); 

     /* 
     * Button helper. Disable animations, hide close button, change title type and content 
     */ 

     $('.fancybox-buttons').fancybox({ 
      openEffect : 'none', 
      closeEffect : 'none', 

      prevEffect : 'none', 
      nextEffect : 'none', 

      closeBtn : false, 

      helpers : { 
       title : { 
        type : 'inside' 
       }, 
       buttons : {} 
      }, 

      afterLoad : function() { 
       this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : ''); 
      } 
     }); 


     /* 
     * Thumbnail helper. Disable animations, hide close button, arrows and slide to next gallery item if clicked 
     */ 

     $('.fancybox-thumbs').fancybox({ 
      prevEffect : 'none', 
      nextEffect : 'none', 

      closeBtn : false, 
      arrows : false, 
      nextClick : true, 

      helpers : { 
       thumbs : { 
        width : 50, 
        height : 50 
       } 
      } 
     }); 

     /* 
     * Media helper. Group items, disable animations, hide arrows, enable media and button helpers. 
     */ 
     $('.fancybox-media') 
      .attr('rel', 'media-gallery') 
      .fancybox({ 
       openEffect : 'none', 
       closeEffect : 'none', 
       prevEffect : 'none', 
       nextEffect : 'none', 

       arrows : false, 
       helpers : { 
        media : {}, 
        buttons : {} 
       } 
      }); 

     /* 
     * Open manually 
     */ 

     $("#fancybox-manual-a").click(function() { 
      $.fancybox.open('1_b.jpg'); 
     }); 

     $("#fancybox-manual-b").click(function() { 
      $.fancybox.open({ 
       href : 'conscious-video.html', 
       type : 'iframe', 
       padding : 5 
      }); 
     }); 

     $("#fancybox-manual-c").click(function() { 
      $.fancybox.open([ 
       { 
        href : '1_b.jpg', 
        title : 'My title' 
       }, { 
        href : '2_b.jpg', 
        title : '2nd title' 
       }, { 
        href : '3_b.jpg' 
       } 
      ], { 
       helpers : { 
        thumbs : { 
         width: 75, 
         height: 50 
        } 
       } 
      }); 
     }); 


    }); 
</script> 

<!------Autoresponder----> 
<script type="text/javascript"> 
    /* <![CDATA[ */  
    $(document).ready(function() { 
     var close_note = $("#note"); 
     close_note.click(function() { 
      j("#note").slideUp(1000, function() { 
       j(this).hide(); 
      }); 
     }); 

     $("#ajax-contact-form").submit(function() { 
      $('#load').append('<center><img src="images/ajax-loader.gif" alt="Currently Loading" id="loading" /></center>'); 

      var fem = $(this).serialize(), 
       note = $('#note'); 

      $.ajax({ 
       type: "POST", 
       url: "contact.php", 
       data: fem, 
       success: function(msg) { 
        if (note.height()) {   
         note.slideUp(1000, function() { 
          $(this).hide(); 
         }); 
        } 
        else note.hide(); 

        $('#loading').fadeOut(300, function() { 
         $(this).remove(); 
         if(msg === 'OK') { 
          $('input').val(""); 
          $('textarea').val(""); 
         } 
         // Message Sent? Show the 'Thank You' message and hide the form 
         result = (msg === 'OK') ? '<div class="success">Your message has been sent. Thank you!</div>' : msg; 

         var i = setInterval(function() { 
          if (!note.is(':visible')) { 
           note.html(result).slideDown(1000); 
           clearInterval(i); 
          } 
         }, 40);  
        }); // end loading image fadeOut 
       } 
      }); 

      return false; 
     }); 
    }); 
    /* ]]> */ 
</script> 
+1

在jQuery中包含两个不同的(在这种情况下非常不同)版本的jQuery永远是灾难的秘诀。如果联系表单代码真的依赖于这种古老版本的库,那么它可能不应该被使用。 – Pointy 2014-08-27 13:58:41

+0

为什么包含jQuery的两个版本?使用一个或另一个。 – sbeliv01 2014-08-27 13:58:58

+0

我刚刚回答了一个类似的问题:http://stackoverflow.com/questions/25522507/jquery-not-loading-properly-in-ie/ – melancia 2014-08-27 14:13:00

回答

1

不要在同一页面内使用两个版本的jQuery(不推荐)。

jQuery.noConflict() 

当你使用两个不同的库来争夺$(这是jQuery的别名)时应该使用它。

许多JavaScript库使用$作为函数或变量名称,只是像jQuery那样使用 。在jQuery的情况下,$是jQuery的别名,所以 所有功能都可以在不使用$的情况下使用。如果您需要使用 另一个JavaScript库以及jQuery,请将$ back 的控制权返回给另一个库,并调用$ .noConflict()。旧的引用 $在jQuery初始化期间被保存; noConflict()只是简单地将它们恢复为 。

可是......你的情况...文档说:

如果由于某些原因的jQuery的两个版本,加载(这是不 推荐),调用$ .noConflict(真)从第二个版本 将全局范围的jQuery变量返回到第一个版本的 版本。

更多信息:http://api.jquery.com/jquery.noconflict/

好运。