javascript - 如何使用 jquery 将 css 添加到 iframe 中?
问题描述
我正在尝试将CSS(width:100%)
使用 jquery 添加到 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);
});
解决方案
代替
iframe.css='width:100%;';
我写这个
iframe.setAttribute( "Style", "width : 100%;");
推荐阅读
- r - 如何获得加权数据的威布尔分布
- android - Google Play 控制台:使用 mapping.txt / proguard-rules.pro 的启动前崩溃报告中的行号不正确
- react-native-reanimated - 如何在 panGestureHandler 中制作滚动视图 scrolllabe?
- java - 如何比较列表和方法中的值?
- mongodb - 如何仅基于日期而不是时间戳获取过滤 mongodb 文档?
- xml - 如何解决此“Cvc-elt.1.a:找不到元素'soap:Envelope'的声明。,'2'行,'63'列”
- angular - 为什么在尝试使用 Angular 检索数据库信息时出现错误 415?
- java - Java Iterator - 不能从静态上下文引用非静态方法 getID()
- c# - Uri Path 与 Java.IO.File 不兼容
- python - 如何在 Python 的 print 语句中获取准确克隆字符的空间?