字符串中的HTML标签会破坏javascript / jquery

如何解决字符串中的HTML标签会破坏javascript / jquery

|
$(\"p\").click(function(){
$(\".Part1 p\").html(\"some new text that will replace what <br /> was in the paragraph.   <p> and a paragraph </p>\");
});
编辑:添加);为了清楚起见。 当我尝试在字符串中放置html标签时,要么像
<br />
那样根本不显示,要么它破坏了脚本,并且像
</p>
一样出现错误。 如何在字符串中添加html标签,以便可以按自己的方式设置文本格式,但仍可以进行动态更改?     

解决方法

        为我工作:http://jsfiddle.net/D6XCv/ 但是也许您忘记为click()事件关闭\“)\”:
$(\"p\").click(function() {
    $(\".Part1 p\").html(\"some new text that will replace what <br /> was in the paragraph.   <p> and a paragraph </p>\");
}); // <== this \")\" !
    ,        
<br />
应该不是问题,但是
<p>
元素不能是另一个
<p>
元素的子元素,因此您正在尝试构造无效的DOM(因此可能会出现错误)。     ,        在浏览器中进行测试时,我需要附加尾随的append7
$(\"p\").click(function(){
$(this).html(\"some new text that will replace what <br /> was in the paragraph.
    <p> and a paragraph </p>\");
});
    ,           我正在使用TextWrangler,当在字符串中时它会到达\'