我的jquery文件中一直出现错误:“未捕获的TypeError:无法调用方法'click'的null (匿名函数)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
});
答案 0 :(得分:0)
似乎是冲突,您可以使用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);
希望这有帮助!