使用jquery .html()插入html [英] Insert html using jquery .html()
问题描述
我想在预先存在的< td>
中插入一大块html。我正在使用这种方法:
I want to insert a large chunk of html into a pre-existing <td>
. I am using this method:
$("td#content").html(LOTS_OF_HTML_CODE_HERE);
但它不起作用。我是一个菜鸟,HTML块中有很多引号和'
似乎正在打破它。这样做的正确方法是什么?
But it doesn't work. I am a noob, there are a lot of quotes and '
within the HTML chunk that seems to be breaking it. What is the correct method for doing this?
推荐答案
我建议将html统一为一个字符串...就像这样。
I would suggest unifying the html into one string... like so.
htmlStr = "";
htmlStr += "<p>some paragraph";
htmlStr += "<p>another paragaraph</p>";
$("#content").html(htmlStr);
通过这种方式,您可以看到您的html发生故障,并为javascript创建了大量可读性内容。
this way you can see where your html is breaking down and it adds a lot of readability to javascript created content.
此外...
如果此TD中有您想要保留的内容,我会使用 append()
jquery方法。
if there is content in this TD that you'd like to keep, I would use the append()
jquery method.
jquery文档是您最好的朋友!
这篇关于使用jquery .html()插入html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!