我想使用jQuery將一個onclick屬性添加到包含href中的某個域的鏈接。沒有錯誤,但由於某種原因,它不起作用我的jQuery語法有問題嗎?
注意:[% property_info.Website %]
是一個模板系統標記,在文本到達瀏覽器時爲止。
$(document).ready(function(){
var hotelWebsite = "[% property_info.Website %]";
$('a[href*="'+hotelWebsite+'"]').attr('onclick', 'pageTracker._link(this.href); return false;');
});
你嘗試用Firebug調試'hotelWebsite'的值嗎? – JMax 2012-03-01 15:27:15
爲什麼不使用正確的jQuery ['on()'](http://api.jquery.com/on)方法綁定事件? – Matt 2012-03-01 15:27:41
return:false無效javascript – Guillaume86 2012-03-01 15:28:43