来自多个选择器的.HTML()

Ror*_*ley 1 html javascript jquery

我有以下jsfiddle,代码如下:

HTML:

<div id="one" style="display:none">One</div>
<div id="two" style="display:none">Two </div>
<div id="three" style="display:none">Three</div>
<div id="output"></div>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#output").html($("#one,#two").html());
Run Code Online (Sandbox Code Playgroud)

我可以使用一个选择器,我想要做的是使用多个选择器,我似乎是错误的方式.有人能指出我正确的方向吗?

谢谢

Cur*_*urt 7

.html() 只会从匹配选择器规则的第一个元素中获取内容:

获取匹配元素集中第一个元素的HTML内容.

资料来源:http://api.jquery.com/html/


如果您想要两个元素的内容,您应该这样做:

$("#output").html($("#one").html() + $("#two").html());
Run Code Online (Sandbox Code Playgroud)

见演示:http://jsfiddle.net/sshg7/2/