使用jQuery的.html方法时多行 [英] Multiple lines when using jQuery's .html method

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

问题描述

当我使用jQuery的html方法时,我希望有多行:

I would like to have multiple lines when I use jQuery's html method, like this:

$("#someID").html("
    <h1>Headline 1</h1>
    <h1>Headline 2</h1>
    ");

但是此代码段不起作用.使用jQuery的html方法时,是否可以使用多行?

However this snippet of code does not work. Is there a way to use multiple lines when using jQuery's html method?

推荐答案

您可以使用字符串串联来加入新行.也很干净.

You could use string concatenation to join the new lines. Its clean too.

$("#someID").html("" +
    "<h1>Headline 1</h1>" +
    "<h1>Headline 2</h1>");

这篇关于使用jQuery的.html方法时多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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