2012-11-09 89 views
0

我試圖爲id和onclick添加一個attr,它在firefox和chrome上工作,但由於某些原因,它不適用於IE 9。 任何替代或東西是錯誤的我的代碼?Jquery attr不適用於IE 9?

$(".extendedGridView tr td a").each(function (index) 
{ 
    if ($(this).html() == "Update") 
    { 
     $(this).attr('id', 'insertButton'); 
     $(this).attr('onclick', "return Validate('extendedGridView')"); 
    }   
}); 
+0

你可以嘗試改變'的.html()''來的.text()' – freebird

+0

其進入,如果因爲我嘗試過的警惕和它的工作 – rtp

+0

爲什麼你將相同的id分配給該td中的所有鏈接,freebird是正確的。 – Jai

回答

6

不要爲此使用attr。使用

this.id = 'insertButton'; 
$(this).click(function(){return Validate('extendedGridView')}); 

另請注意,如果有返回或空格或任何標記,使用html()檢查文本將不起作用。首選此測試:

if ($(this).text().trim() == "Update") { 

然後,確保每個元素都有不同的id。在你的代碼中,你是否確定這一點還不清楚,但是當你使用each時,我恐怕不是這樣。如果你需要的是讓你的元素可選擇更容易,使用類:

$(this).addClass('update'); 
+0

mwahhh我愛你的男人哈哈非常感謝! – rtp

相關問題