C# 将IFRAME标记放置在DIV标记内
我有一个HTML字符串,其中包含许多HTML标记,包括iframe:C# 将IFRAME标记放置在DIV标记内,c#,html,C#,Html,我有一个HTML字符串,其中包含许多HTML标记,包括iframe: <iframe width="40" other-properties> iframe code </iframe> iframe码 如何将HTML字符串中的所有iframe标记放入DIV中,如下所示: <div class="video"> <iframe width="40" other-properties> iframe code </
<iframe width="40" other-properties>
iframe code
</iframe>
iframe码
如何将HTML字符串中的所有iframe标记放入DIV中,如下所示:
<div class="video">
<iframe width="40" other-properties>
iframe code
</iframe>
</div>
iframe码
一个简单的替换看起来就足够了
var newString = originalString.Replace("<iframe", "<div class='video'><iframe").Replace("</iframe>", "</iframe></div>");
var newString=originalString.Replace(一个简单的Replace
看起来就足够了
var newString = originalString.Replace("<iframe", "<div class='video'><iframe").Replace("</iframe>", "</iframe></div>");
var newString=originalString.Replace(“您可以使用jQuery进行此操作
它甚至适用于尚未添加到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>
var$html=$('Test');
$html.find('iframe').wrap('');
//现在,您可以将$html附加到DOM中
console.log($html[0].outerHTML);//输出:Test
请参阅。您可以使用jQuery进行此操作
它甚至适用于尚未添加到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>
var$html=$('Test');
$html.find('iframe').wrap('');
//现在,您可以将$html附加到DOM中
console.log($html[0].outerHTML);//输出:Test
请参阅。@KieranQuinn,为什么要在服务器端字符串中包含HTML?HTML字符串来自数据库…HTML字符串是通过CMS插入的。您当前如何传递该字符串(假设只有一个字符串而不是多个)到dom?如果有的话,为什么要把它放在一个DIV里?@WouterHuysentruit能够制作一个YouTube视频responsive@KieranQuinn,为什么在服务器端字符串中包含HTML?HTML字符串来自数据库…HTML字符串是通过CMS插入的。您当前如何传递该字符串(假设有一个字符串而不是多个)到dom?如果有的话,为什么要将其放在DIV中?@WouterHuysentruit能够使YouTube视频响应