我正在使用jquery綁定鏈接上的一些點擊事件。使用下面的代碼,我可以通過ajax改變鏈接的href - 但是當href改變時,我嘗試點擊鏈接,沒有任何反應。通過Ajax更改jQuery中的鏈接
想知道是否有人可以發現我失蹤的明顯錯誤。
$('a.shortlist_action').bind('click',function(){
item = $(this);
href = item.attr('href');
parent = $(this).parent('.shortlist_action_container');
item = $(this);
$.ajax({
url: $(this).attr('href'),
success: function(data) {
item.addClass('largeviewplannerbutton');
item.attr("href", '/myaccount/planner');
}
}
});
// stop event propagation here
return false;
});
謝謝。
沒有答案,只是一些筆記。你有'item = $(this);'兩次,你可能想使用'url:href'而不是'url:$(this).attr(href)'。 – yoozer8
第一次點擊鏈接會執行Ajax並更改href,然後第二次和隨後的點擊實際上會導航到新的URL,而無需進一步的Ajax?這對用戶來說不是有點混淆嗎? – nnnnnn
嗨,人們將點擊鏈接將項目添加到列表中,如書籤。一旦他們點擊了鏈接,按鈕就會變成「查看列表」按鈕。 – doubleplusgood