作为模板的一部分,我网站的每个页面上都有一个带有特定 ID(“容器”)的 DIV。
#container
{
max-width:980px; min-width:980px; padding-top:6px;
}
单击按钮(切换全屏)时,我会得到客户端支持的最大宽度,然后执行以下操作:
document.getElementById('container').setAttribute('style', 'max-width:' + width + 'px !important;');
document.getElementById('container').setAttribute('style', 'min-width:' + width + 'px !important;');
这工作正常并将最大宽度设置为 1400 像素。
我的问题是,我可以使用 javascript 删除我刚刚添加的样式,这样只有 css 会应用吗?
或者我的选项是否有相同的代码,回到 980?
document.getElementById('container').setAttribute('style', 'max-width:980px !important;');
document.getElementById('container').setAttribute('style', 'min-width:980px !important;');
您可以删除整个 style
属性
document.getElementById('container').removeAttribute('style');
或者您可以只删除 style
属性中的 chiều rộng tối đa
tài sản:
document.getElementById('container').style.maxWidth = "none";
引用资料:
style
removeAttribute
Tôi là một lập trình viên xuất sắc, rất giỏi!