我希望能够动态地移除或禁用一个如下所示的
<style>
标签。<style type="text/css" id="cssx/portal/simple-sidebar.css" designtr="cssx/portal/simple-sidebar.css">
#wrapper {
padding-left: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#wrapper.toggled {
padding-left: 250px;
}
#sidebar-wrapper {
z-index: 1000;
position: fixed;
left: 250px;
width: 0;
height: 100%;
margin-left: -250px;
overflow-y: auto;
background: #000;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
</style>
如果我有ID或自己定义的designtr属性,似乎无法像这样禁用或删除它:
var id = 'x';
var designtr = 'x';
document.getElementById(id).disabled = true; //doesn't work, throws an error saying element is null
$('style[designtr="' + designtr + '"]').remove(); //doesn't work, although strangely no error thrown
我曾经在某个地方读到过,即使使用HTML5,样式标签也不能具有有效的id属性。
我想做的就是根据手头上的某个唯一id,删除或禁用一个样式标签。
$(document).ready(function(){ your code });
中。 - JackWid
吗? - Joaquín O