如何使用jquery追加数据?

我需要使用dom将值添加到span中。 但现在我正在使用字符串操作。 如何将其更改为dom或附加值。 我需要使用dom获取html formate中的返回值。

将layer.id定义为一些文本,这将在所有span元素内容中替换

$.each($("span"),function(){ $(this).html(layer.id); }); 

谢谢

你可以附加如下:

 $('.ClassName').append('

Test

');
 $('#id').after('

Test

'); $('#id').before('

Test

');

试试这个:

 $("
  • " + preElement + "").appendTo('ul.class'); //----------^^^^^ // use the id // or class of //the specific ul
  • 使用appendTo()代替返回并将其追加到元素中。

    (as i see you are returning li then append it to the ul)