-1

現在、HTML(XMLファイルから取得)を変数に保存しようとしていますが、どういうわけか奇妙なエラーが発生します。それに加えて、私が使用していなくても、ブラウザはそのHTMLコードで使用されている画像を読み込もうとしているようです。

コードは次のとおりです。

// Load the data from the XML node.
var description = $(this).find('description').text();

var descriptionWithTags = description.replace('<p>','');
descriptionWithTags = descriptionWithTags.replace('</p>','########');

// Remove HTML Tags and add the Line-Breaks
var convertedString = $(descriptionWithTags).text();
convertedString = convertedString.replace('########','<br /><br />');
console.log("E");

// Save it in an array.
contentRSS[articleCount] = convertedString;

編集:次の行を削除すると、再び機能しますが、理由はわかりません。

descriptionWithTags = descriptionWithTags.replace('<p>','');
4

1 に答える 1

2

HTMLタグのないテキストから始めます:

var description = $(this).find('description').text(); // this removes HTML tags

次に、それをHTMLとして解析しようとします。

var convertedString = $(descriptionWithTags).text();

これは機能しません。おそらく最初の行でhtmlを使用する必要があります:

var description = $(this).find('description').html();
于 2013-01-13T10:27:50.500 に答える