2011-09-24 113 views
1

在我的應用程序中,我向服務器發送一個AJAX請求,並根據一些數據,我必須更改元素的屬性。這裏是我的代碼:href屬性<a>未設置

$('#unclaimed_codes_list li').map(function(){ 
    $(this).children("a:first").text(fname + ' ' + lname + '(' + key + ')'); 
} 

$.get('/accs/get_val/' + key, function(data){ 
    var edit_href = '/ak_access_levels/' + id + '/edit'; 
    alert(edit_href); 
    $(this).children("a:first").attr('href', 'edit_href'); 
}); 

但它不工作。我可以看到我的edit_href值是正確的,但仍然沒有設置href屬性。我錯過了什麼嗎?謝謝。

+3

我不能相信'$(this)'(在'$ .get')指向一個HTML元素。檢查你的代碼。 –

+1

另外,你正在給內容「edit_href''分配一個字符串給href屬性,而不是'edit_href'變量。 – JJJ

回答

2

$('#unclaimed_codes_list li a:first')代替$(this).children('a:first')的第二次發生。其次,將'edit_href'更改爲edit_href

+0

非常感謝,它的工作原理。我有edit_href,不是'edit_href'反正,$('#unclaimed_codes_list李a:第一')做了伎倆。謝謝。 – rookieRailer