2012-12-11 32 views
0

我需要使用dom将值添加到跨度中。但是现在我正在使用字符串操作。如何将其更改为dom或附加值。我需要获得使用dom的html格式的返回值。如何使用jquery追加数据?

+0

您能否提供更多详细信息关于您需要做什么? – Anass

+0

我需要添加以下语句(span)到html页面使用dom –

+0

请参阅新的代码 –

回答

0

定义layer.id一些文本,这将在所有span元素含量得到更换

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

感谢

+0

谢谢u.but如何访问类 –

0

您可以将喜欢以下:

$('.ClassName').append('<p>Test</p>'); 
0
$('#id').after('<p>Test</p>'); 
$('#id').before('<p>Test</p>'); 
0

尝试与此:

$("<li class='" + liClass + "'>" + preElement + 
    "<label for='" + layer.id + "'>" + layer.name + "</label>").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)

+0

我需要使用setelements,setattributes等完全更改此dom类型。, –

+0

_setelements,setattributes etc_不明白。 – Jai

+0

我的代码工作正常但是。我需要删除跨度和其他刺痛操纵,并使用dom我操纵价值 –