我有在頁面上這個網站:防止鏈接事件無法
<a href="review.asp?sitename=webcamking#video_embed" class="tutorials" data_site="webcamking"> Tutorial 1</a>
這個jQuery:
$('.tutorials').click(function(event){
event.preventDefault();
event.stopPropagation()
var linkText=$(this).text();
var siteName= $(this).attr('data_site');
alert("Test. linkText:"+linkText+". siteName:"+siteName);
_gaq.push(['_trackEvent', 'LinkClicked', siteName, linkText]);
//window.location.href=$(this).attr('href');
return false;
})
的問題是,鏈接仍保持送我到目的地。我需要阻止它。我需要檢查我得到的alert.and希望谷歌分析事件觸發!
更新:修改後的代碼:
$(document).ready(function(){
$('.tutorials').click(function(event){
event.preventDefault();
var linkText=$(this).text();
var siteName= $(this).attr('data_site');
alert("Test. linkText:"+linkText+". siteName:"+siteName);
_gaq.push(['_trackEvent', 'LinkClicked', siteName, linkText]);
//window.location.href=$(this).attr('href');
return false;
});
正常工作對我的jsfiddle http://jsfiddle.net/kchpj/ – DG3 2012-04-24 13:36:47
它是活的靜態link..yeah..no需要() – 2012-04-24 13:39:30
有寫it..may較短方式是我應該添加onclick事件直接鏈接?!?! – 2012-04-24 13:39:51