簡體   English   中英

加載頁面時出現J-Query錯誤

[英]J-Query Error when loading the page

我在我的jquery文件中不斷收到錯誤:“ Uncaught TypeError:無法調用null的方法'click'(匿名函數)jQuery.extend.ready DOMContentLoaded-第2行

jQuery代碼:

  $(document).ready(function () {
      $(".leftImage a").click(function () {
          _gaq.push(['_trackEvent', 'sidebanner', 'click', $(this).attr('id'), 0, true]);
      }); //End Of SideBanners

      $("a[href$='.pdf'], area[href$='.pdf']").click(function () {
          if ($(this).attr("id")) {
              _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('id'), 0, true]);
          } else {
              _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('href'), 0, true]);
          }
      }); //End of pdfs mapping and non mapping

      $("a[href$='.zip']").click(function () {
          if ($(this).attr("id")) {
              _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('id'), 0, true]);
          } else {
              _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('href'), 0, true]);
          }
      }); //End of Zips

  });

似乎是沖突,您可以使用http://api.jquery.com/jquery.noconflict/提供的解決方案進行解決

jQuery.noConflict();

(function( $ ) {

  $(document).ready(function() {

        $(".leftImage a").click(function () {
            _gaq.push(['_trackEvent', 'sidebanner', 'click', $(this).attr('id'), 0, true]);
        }); //End Of SideBanners

        $("a[href$='.pdf'], area[href$='.pdf']").click(function () {
            if ($(this).attr("id")) {
                _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('id'), 0, true]);
            } else {
                _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('href'), 0, true]);
            }
        }); //End of pdfs mapping and non mapping

        $("a[href$='.zip']").click(function () {
            if ($(this).attr("id")) {
                _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('id'), 0, true]);
            } else {
                _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('href'), 0, true]);
            }
        }); //End of Zips

  });

})(jQuery);

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM