我有以下 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>
jQuery:
$("#output").html($("#one,#two").html());
我可以让它与一个选择器一起工作,我想做的是使用多个选择器,我似乎以错误的方式去做。有人可以指出我正确的方向吗?
谢谢
最佳答案
.html()
只会从匹配选择器规则的第一个元素中获取内容:
Get the HTML contents of the first element in the set of matched elements.
来源:http://api.jquery.com/html/
如果您想要来自两个元素的内容,您应该这样做:
$("#output").html($("#one").html() + $("#two").html());
关于javascript - 来自多个选择器的 .HTML(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11967420/