0

私はこれを持っています、そしてそれは動作します:

local.Source = $('article.hero-unit').html();
$('#Source').text(local.Source);

しかし、私がやりたいのはこれです:

local.Source = $('article.hero-unit').html();
$('fieldset').append(local.Source);

問題は、append メソッドが html を追加し、< 記号をエスケープしないことです。

4

3 に答える 3

1

試す

local.Source = $('article.hero-unit').html();
var $fieldset = $('fieldset');
$fieldset.text($fieldset.text()+local.Source);

パラメータなしで呼び出す.text()と、要素内に既にあるテキストが取得されます。これは、html を追加するlocal.Sourceだけです。

于 2013-03-14T23:47:45.207 に答える
1

そのテキストを<span>要素に入れます:

$('<span>', {
    text: local.Source
}).appendTo('fieldset');
于 2013-03-14T23:49:08.530 に答える
0

これでうまくいくと思います:

local.Source = $('article.hero-unit').html();
local.Legend = $('fieldset legend').text();
$('fieldset').text(local.Source);
$('fieldset').prepend('<legend>' + local.Legend + '</legend>');
于 2013-03-15T00:18:25.180 に答える