将IFRAME标记放在DIV标记内

时间:2015-11-30 12:49:53

标签: c# html

我有一个HTML字符串,其中包含许多HTML标记,包括iframe:

<iframe width="40" other-properties>
   iframe code
</iframe>

如何将HTML字符串中的所有iframe标记放入DIV中,如下所示:

<div class="video">
  <iframe width="40" other-properties>
     iframe code
  </iframe>
</div>

2 个答案:

答案 0 :(得分:2)

您可以使用jQuery wrap

它甚至适用于尚未添加到DOM的元素:

var $html = $('<section><h1>Test</h1><iframe width="40"></iframe></section>');
$html.find('iframe').wrap('<div>');

// now you can append $html to the DOM

console.log($html[0].outerHTML); // Outputs: <section><h1>Test</h1><div><iframe width="40"></iframe></div></section>

请参阅JSFiddle

答案 1 :(得分:1)

一个简单的HAVING COUNT看起来就够了

Replace