0

我使用引导模式来显示使用外部 CSS 文件应用的 CSS 的内容。我将此模态集成到一个网页中,其中的元素具有与我的模态相似的类名。如何使网页 css 样式不适用于我的模态?我已经使用$('link[href="responsive.css"]').prop('disabled',true); 了上面的代码在对话框和网页中都禁用了 CSS 文件。我只需要从我的模态中删除它。

4

1 回答 1

0

使用document.styleSheetsAPI 查找有问题的样式表,并disabled仅在模式打开时将属性设置为 true:

function reenable_stylesheets()
  {
  "use strict";
  Array.from(document.styleSheets).map(
    function(value) 
    {
    value.disabled = false;
    });
  }
   
function disable_and_replace_stylesheet(val)
  {
  "use strict";
  Array.from(document.styleSheets).map(
    function(value) 
    {
    return value.href;
    }).reduce
       (
       function(prevalue, curvalue, index, data) 
         {
         disable_and_replace_stylesheet.index = !!RegExp(val).test(curvalue) ? index : undefined; 
         }
       );

  if (disable_and_replace_stylesheet.index)
    {
    console.log(disable_and_replace_stylesheet.index); document.styleSheets[disable_and_replace_stylesheet.index].disabled = true;
    }
  }

/*
document.getElementById("modal_parent").addEventListener("click", function(){disable_and_replace_stylesheet("boot");});

document.getElementById("modal_parent").addEventListener("blur", function(){reenable_stylesheets();});
*/

参考

于 2016-09-26T20:15:31.843 回答