2012-12-11 34 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我操縱價值 –