2014-02-12 146 views
0

我有一个表与tds有id,我需要重新排列列顺序。重新排列表的列

$('table tr').each(function() { 
    var tds = $('#Status'); 
    var tdA = $('#Address'); 
    alert(tds.innerHtml);   //Here am getting a blank msg    
    tds.remove().insertAfter(tda); //This is what i need to do 
}); 
+0

请分享你的HTML以及..看起来你有'#Status'和'#Address'每一行中....元素的ID必须是唯一的 –

+0

你选择allways相同的ID','$('#状态')'所以他们可能会重复 – reyaner

+0

实际上这是一个ASP中继器 –

回答

1

工作实例与使用:http://jsfiddle.net/eT5pL/
工作与IDS使用例如:http://jsfiddle.net/eT5pL/1/

正如你不应该有重复的ID附加的注释。
仔细检查'#Status'不应该'.Status'

$('table tr').each(function() { 
    var tds = $(this).find('#Status'); //find the child of the row 
    var tdA = $(this).find('#Address'); //find the child of the row   
    tds.remove(); 
    $(tds).insertAfter(tdA); 
}); 
+0

这不能是正确的!相同的ID's ...'$(this).find('。Status')' – reyaner

+0

_“它允许在HTML5中”_?你是指重复的ID?不,这不是事实。 ID _必须是唯一的。 – undefined

+0

在这种情况下确实如此......但仍然应该避免它! – reyaner