我正在尝试使用jquery将CSS(width:100%)
添加到iframe中。但是我不知道我哪里做错了。我尝试了下面提到的代码,使用jquery在iframe中添加CSS。HTML文件
<div class="col-md-12">
<div class="page-content ask-question" style="margin-top: 5px;">
<div id="preview-container" style="height: 342px;">
</div>
</div>
</div>
Jquery代码
$('.ace_text-input').keyup(function(e) {
delay(function(){
var html1 = buildSource(html, js, css);
var iframe = document.createElement('iframe');
iframe.src = 'about:blank';
iframe.frameBorder="0";
iframe.height = 496;
iframe.css='width:100%;';
iframe.className = 'preview-iframe';
$('.preview-iframe').remove();
$('div#preview-container').append(iframe);
iframe.contentWindow.document.open('text/html', 'replace');
iframe.contentWindow.document.write(html1);
iframe.contentWindow.document.close();
},1000);
});
发布于 2019-04-14 02:24:55
而不是
iframe.css='width:100%;';
我写这篇文章
iframe.setAttribute( "Style", "width : 100%;");
发布于 2019-04-14 02:15:37
您可以使用Javascript
对元素应用width
。查看下面的代码片段。谢谢
var iframe = document.createElement('iframe').style.width = "100%";
https://stackoverflow.com/questions/55668252
复制相似问题