【发布时间】:2018-06-20 11:52:31
【问题描述】:
我有以下 html 代码
<div class="main">
<div id="magicdomid2" class="">
<center style="width:100%;margin:0 auto;list-style-position:inside;display:block;text-align:center">
<h1><span class="b"><b>Welcome to Etherpad!</b></span></h1>
</center>
</div>
<div id="magicdomid3" class=""><br></div>
<div id="magicdomid4" class="">
<span class="">This pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!
</span>
</div>
<div id="magicdomid5" class=""><br></div>
<div id="magicdomid6" class="">
<span class="">Get involved with Etherpad at </span>
<span class=" url"><a href="http://etherpad.org">http://etherpad.org</a>
</span>
</div>
</div>
这里是html内容
var html = $(".main").html();
我需要在变量中获取以下htm
<div class="main">
<center style="width:100%;margin:0 auto;list-style-position:inside;display:block;text-align:center">
<h1><span class="b"><b>Welcome to Etherpad!</b></span></h1>
</center>
<br>
<span class="">This pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!
</span>
<br>
<span class="">Get involved with Etherpad at </span>
<span class=" url"><a href="http://etherpad.org">http://etherpad.org</a>
</span>
</div>
我尝试了以下代码
var text = $('div.main div').contents().unwrap().siblings('div').remove();
变量“text”将得到一个对象,我需要一个变量中的html内容。请帮我找到它。
他们是否有可能从 etherpad 导出自定义的 html 或 xml 格式?
【问题讨论】:
-
为您想要作为字符串获取的元素提供
id并使用它。alert(document.getElementById('main_div').outerHTML) -
试试 var text = $('div.main').contents().unwrap('div');
标签: javascript jquery html etherpad