2012-11-09 59 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

相关问题