[英]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.