为什么不设置“禁用”?的属性通过 JavaScript 标记可以在 IE 8 中工作吗?
我正在实现一个 JavaScript 函数,该函数启用/禁用网站的两个 CSS 文件:
function switch_style ()
{
var i, link_tag ;
for (i = 0, link_tag = document.getElementsByTagName("link"); i < link_tag.length ; i++ )
{
if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) && link_tag[i].title)
{
if(link_tag[i].title == "normal")
{
link_tag[i].disabled = true;
}
else if (link_tag[i].title == "contrast")
{
link_tag[i].disabled = false;
}
}
}
set_cookie( style_cookie_name, "contrast", style_cookie_duration );
}
如您所见,我启用或禁用链接标记。这适用于所有浏览器,但不适用于 IE8。
有已知的原因吗?
I am implementing a JavaScript function that enables/disables two CSS file of a website:
function switch_style ()
{
var i, link_tag ;
for (i = 0, link_tag = document.getElementsByTagName("link"); i < link_tag.length ; i++ )
{
if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) && link_tag[i].title)
{
if(link_tag[i].title == "normal")
{
link_tag[i].disabled = true;
}
else if (link_tag[i].title == "contrast")
{
link_tag[i].disabled = false;
}
}
}
set_cookie( style_cookie_name, "contrast", style_cookie_duration );
}
As you can see, I enable or disable a link tag. This works in all browsers but not in IE8.
Is there a known reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在切换的
disabled
属性link
元素。正如 MDC 上所说,要从 DOM 中删除
link
元素,请使用element .removeChild
。只是一个愚蠢的例子:如果您想删除页面上的第一个
link
元素,只需在浏览器的地址栏中输入此 JavaScript 函数即可:(我刚刚尝试过,看起来很有趣:)
You're toggling the
disabled
property oflink
elements. As said on MDC,To remove a
link
element from the DOM, useelement.removeChild
.Just a stupid example: if you want to remove the first
link
element on a page, just enter this JavaScript function in your browser's location bar:(I just tried it on SO, looked funny :)
如果您使用
removeAttribute('disabled')
而不是将其设置为 false 会怎样?what if you use
removeAttribute('disabled')
instead of setting it to false?