样式=“显示:块;"适用于 Chrome 但不适用于 Safari [英] Style="display:block;" works in Chrome but not Safari

查看:75
本文介绍了样式=“显示:块;"适用于 Chrome 但不适用于 Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个横幅,默认情况下不显示.我用来让它显示的代码是

I have a banner on my website that by default is not shown. The code I am using to get it to show is

document.getElementById("cookie1").style = "display:block;"

这在 Chrome 中有效,但在 safari 中无效.我在 Safari 中也没有收到任何错误,只是没有显示横幅.

This works in Chrome but is not working in safari. I am not getting any errors in Safari either, It just doesn't show the banner.

关于什么可能导致这种情况的任何想法?或者隐藏/显示页面元素的更好方法?

Any ideas on what could be causing this? Or a better way to hide/show a page element?

谢谢!

推荐答案

从 Chrome 和 Safari 中的测试来看,Chrome 似乎更宽容,因为它解析样式字符串并为您放置正确的样式,但 Safari才不是.

From testing this in Chrome and Safari, it seems Chrome is more forgiving in that it parses the style string and puts the right style in place for you, but Safari does not.

试试:

document.getElementById("cookie1").style.display = 'block';

无论如何最好是明确的,而不是依赖于样式本身的字符串解析.

It's probably best to be explicit like that anyway, instead of relying on string parsing for the style itself.

这篇关于样式=“显示:块;"适用于 Chrome 但不适用于 Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆