javascript - 将 .css 文件附加到 iframe,以便可以覆盖样式

标签 javascript jquery css iframe

我正在尝试这样:

$(document).ready(function(){
    $('#muestraMotor').bind('mousedown',function(){
        var cssLink = document.createElement("link");
        cssLink.href = "../estilo/css/datepicker.css";  cssLink .rel = "stylesheet";  
        cssLink .type = "text/css";  
        frames['cboxIframe'].document.body.appendChild(cssLink); 
    });
})

其中 cboxIframe 是 iframe 的 id,

Firebug 跳跃:

frames.cboxIframe is undefined
[Detener en este error] frames['cboxIframe'].document.body.appendChild(cssLink);

-编辑-

我现在这样试试

$(document).ready(function(){
    $('#txtRsvButtonGold').bind('mousedown',function(){
        var $head = $("iframe#cboxIframe").contents().find("head");                
        $head.append($("<link/>", { rel: "stylesheet", href: "http://sameDomain.com/css/datePicker.css", type: "text/css" }));

    });
});

没有错误,但我看不到带有 Firebug 的 .css 文件(并且没有应用 corse 样式)

最佳答案

您需要传递框架的 name 属性(或其在页面上的数字索引),而不是将 id 传递给 frames

关于javascript - 将 .css 文件附加到 iframe,以便可以覆盖样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8299766/

相关文章:

javascript - 从 gmail 中获取 html 表并使用 google apps 脚本放入 google 表格中

javascript - 在 anchor 标记之前执行函数并在 anchor 标记之后加载它

javascript - Couchdb 对带有字符串的大型文档的 View 作为键超时

javascript - jQuery 代码在 while 循环中不起作用

javascript - 如何在自定义列表组中的点击事件上添加事件类?

javascript - 如何使用 JQuery 查找上个月上周的第一天

javascript - 使 div 在 foreach 循环中出现的问题

javascript - 如何观察 'a' 标签的内容 - jquery

html - 如何获取导航栏后面的图像

css - 使用类名和 React 看不到我的类?