0
我使用引导模式显示使用外部CSS文件应用CSS的内容。我将这个模式集成到了一个网页中,其元素类名与我的模态相似。我如何使网页的CSS样式不适用于我的模式?我已经使用$('link[href="responsive.css"]').prop('disabled',true);
上面的代码禁用了对话框和网页中的CSS文件。我只需要从我的模式中删除它。如何禁用引导模式的外部css文件?
我使用引导模式显示使用外部CSS文件应用CSS的内容。我将这个模式集成到了一个网页中,其元素类名与我的模态相似。我如何使网页的CSS样式不适用于我的模式?我已经使用$('link[href="responsive.css"]').prop('disabled',true);
上面的代码禁用了对话框和网页中的CSS文件。我只需要从我的模式中删除它。如何禁用引导模式的外部css文件?
使用document.styleSheets
API来找到问题的样式表,并设置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();});
*/
参考
在这里提供一些代码。 –
我在模态页面中只使用了上面提到的代码。有两个文件一个是网页,另一个是模态代码页。我已经使用iframe在网页中集成了模态页面 – user2083041