javascript-使用jQuery解开div元素后如何查找html
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-使用jQuery解开div元素后如何查找html,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2633字,纯文字阅读大概需要4分钟。
内容图文
![javascript-使用jQuery解开div元素后如何查找html](/upload/InfoBanner/zyjiaocheng/668/eb48b48c18b6414f971e4fe0a1b59a42.jpg)
我有以下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();
变量“文本”将得到一个对象,并且我需要变量中的html内容.请帮助我找到它.
他们有可能从etherpad导出定制的html或xml格式吗?
解决方法:
希望有帮助!
var htm = "";
$("div[id^='magicdomid']").each(function(i,val){
htm = htm + $(this).html();
});
$("div[class='main']").empty().html(htm);
//You can also use this for the same
$("div[id^='magicdomid']")
.contents()
.filter(function() {
return this.nodeType === 1;
})
.unwrap()
.end()
.filter(function() {
return this.nodeType === 3;
})
.remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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>
内容总结
以上是互联网集市为您收集整理的javascript-使用jQuery解开div元素后如何查找html全部内容,希望文章能够帮你解决javascript-使用jQuery解开div元素后如何查找html所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。