tun*_*2fs 3 html javascript jquery
我有一个HTML字符串.因为我需要对它进行一些操作,我需要使用jquery.但是我有问题,jQuery在字符串中添加了额外的标签.我怎么能避免这种情况.
var html = marked(input); //returns an html string
console.log(html); //prints: <p>test<div>Type</div></p>
var tree = $("<div>" + html + "</div>");
//generate html out of the jquery html
html = tree.html();
console.log(html); // now it is: <p>test</p><div>Type</div><p></p>
Run Code Online (Sandbox Code Playgroud)
我用jQuery 2.0.3和浏览器测试了它的firefox和chrome.
一个<div>内部的<p>无效HTML.
http://www.w3.org/TR/html401/struct/text.html#h-9.3.1
看来DOM正在尝试通过打开/关闭无效<p>标记来为您修复它.