JavaScript将HTML保存在一个变量中
JavaScript saving HTML in a variable
我目前试图保存一些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>','');
你从一个没有HTML标签的文本开始:
var description = $(this).find('description').text(); // this removes HTML tags
然后尝试解析为HTML:
var convertedString = $(descriptionWithTags).text();
这不能工作。你应该在第一行使用html:
var description = $(this).find('description').html();
相关文章:
- 导航到特定事件的另一个变量页面
- 我可以在Javascript/jQuery中使用一个变量作为键吗
- 使用mongodb更新中的一个变量
- 将节点数据分配给另一个变量jstree
- Javascript:在激发函数后返回一个变量以供使用
- 替换另一个变量对象中的变量值
- 什么'它的意思是当一个变量位于括号外时
- 可以't将sessionStorage设置为Javascript中的一个变量
- 在Flickr API的标签参数中传递一个变量
- 从Jquery函数中获取一个变量
- 为两个ID设置一个变量的正确语法
- 如何将变量值附加到另一个变量
- 通过加载函数发送一个变量
- 如何将一个变量从一个控制器传递到合金中的另一个控制器
- 如何在Jquery函数中为自动完成文本区域指定一个变量作为Id
- Javascript未在其中一个变量上输出0
- 保留“;这个“;在一个变量中;这个“;使用此变量
- 是否可以在另一个变量中使用未声明的变量
- JS/ANGULAR使用一个变量's值作为另一个对象的键
- 如何每秒从一个变量中提取一定次数的javascript/html