Javascript 加载页面时出现J-Query错误
我的jquery文件中不断出现错误:UncaughtTypeError:无法调用null的“click”方法 匿名函数jQuery.extend.ready DOMContentLoaded-第2行 Jquery代码:Javascript 加载页面时出现J-Query错误,javascript,jquery,console,Javascript,Jquery,Console,我的jquery文件中不断出现错误:UncaughtTypeError:无法调用null的“click”方法 匿名函数jQuery.extend.ready DOMContentLoaded-第2行 Jquery代码: $(document).ready(function () { $(".leftImage a").click(function () { _gaq.push(['_trackEvent', 'sidebanner', 'click', $(t
$(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库吗?你在Joomla中使用这段代码吗?或者类似的?请给我们更多的细节。非常感谢Heldrida。
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);