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