我有下面的代碼:我應該繼續使用的document.ready Jquery的
$(document).ready(function(){
$('td.rightImage, .leftImage a').click(function(){
if($(this).attr("id")){
_gaq.push(['_trackEvent', 'sidebanner', 'click', $(this).attr('id'),0,true]);
}
else{
_gaq.push(['_trackEvent', 'sidebanner', 'click', $(this).attr('href'),0,true]);
}
});
});
$(document).ready(function(){
$("a[href$='.pdf']").click(function(){
_gaq.push(['_trackEvent', 'pdf', 'click',$(this).attr('href'),0,true]);
});
});
$(document).ready(function(){
$("a[href$='.zip']").click (function(){
_gaq.push(['_trackEvent', 'zip', 'download',$(this).attr('href'),0,true]);
});
});
我應該繼續使用的Docment準備每個onclick事件我想如果不是有什麼更好的方式來編寫上面?
感謝
讓它只是一個功能,它們都在同一時間被調用,畢竟。 – George
是!如果使用jQuery或其他框架或純JS,則無關緊要。只要記住當所有元素已經在jQuery中表示'document.ready()'的位置時執行這種代碼。你的腳本在它可用時立即執行 - 甚至在加載HTML文檔之前 - 這就是'document.ready'或'body.onload'代表的! – ElmoVanKielmo