使用 jquery .html() 插入 html [英] Insert html using jquery .html()

查看:33
本文介绍了使用 jquery .html() 插入 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一大块 html 插入到预先存在的 <td> 中.我正在使用这种方法:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆