admin管理员组

文章数量:1325359

I use jquery to request data and then fill them to a table whose id is 'mresholder', it works in webkit and ff but it doesn't work well in IE. It will append those data behind </table>.
How to solve this or what's the alternative way to do this?

for(i=0;i<length;i++)
{
   song=data.results[i];
   o=$('#mresholder').html();
   $('#mresholder').html(o+='<tr sid='+song.song_id+' aid='+song.album_id+'><td class="sname">'+song.song_name+'</td><td class="sartist">'+song.artist_name+'</td><td class="salbum">'+song.album_name+'</td></tr>');
};

I use jquery to request data and then fill them to a table whose id is 'mresholder', it works in webkit and ff but it doesn't work well in IE. It will append those data behind </table>.
How to solve this or what's the alternative way to do this?

for(i=0;i<length;i++)
{
   song=data.results[i];
   o=$('#mresholder').html();
   $('#mresholder').html(o+='<tr sid='+song.song_id+' aid='+song.album_id+'><td class="sname">'+song.song_name+'</td><td class="sartist">'+song.artist_name+'</td><td class="salbum">'+song.album_name+'</td></tr>');
};
Share Improve this question asked Sep 14, 2011 at 15:29 dotslashludotslashlu 3,4015 gold badges33 silver badges58 bronze badges 2
  • 3 Can we see the related HTML as well, please? – Matt Gibson Commented Sep 14, 2011 at 15:30
  • It sounds like #mresholder is another element that contains the table you want to append to rather than the table itself. If that's the case, try editing your search to $('#mresholder table'). – Jonathan Lonowski Commented Sep 14, 2011 at 15:36
Add a ment  | 

2 Answers 2

Reset to default 8

"sid", "aid" aren't valid HTML attributes. Try data-sid, data-aid

also, change

 o=$('#mresholder').html();
 $('#mresholder').html(o+='<tr sid='+song.song_id+' aid='+song.album_id+'><td class="sname">'+song.song_name+'</td><td class="sartist">'+song.artist_name+'</td><td class="salbum">'+song.album_name+'</td></tr>');

to

$('#mresholder').append('<tr data-sid='+song.song_id+' data-aid='+song.album_id+'><td class="sname">'+song.song_name+'</td><td class="sartist">'+song.artist_name+'</td><td class="salbum">'+song.album_name+'</td></tr>');

(.html() to .append())

Try using append instead.

$('#mresholder').append('<tr sid='+song.song_id+' aid='+song.album_id+'>'...);

Also, check the HTML that you're adding, IE has a problem when adding HTML to a table if it's not valid. Try @genesis' suggestion, and change sid and aid to data-sid and data-aid, too.

本文标签: javascriptjQuery html() doesn39t work well in IE9Stack Overflow