我可以依赖显示为工具提示的标题属性吗?
我们在网站中编写简单的工具提示已经有一段时间了,并且刚刚意识到我们可以通过简单地使用“标题”属性来完成同样的事情。我们有什么理由不应该使用 title 属性作为工具提示吗?是否有不支持此功能的浏览器? (w3schools 似乎表明所有主流浏览器都支持这一点。)
We've been coding simple tooltips into our web site for a while, and just realized that we could accomplish the same thing by simply using the "title" attribute. Any reason that we shouldn't use the title attribute as a tooltip? Are there any browsers that don't support this feature? (w3schools seems to indicate that all major browsers support this.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个标准,你应该很安全。
请参阅http://www.w3.org/TR/ html4/struct/global.html#h-7.4.3
It is a standard, you should be pretty safe.
See http://www.w3.org/TR/html4/struct/global.html#h-7.4.3
所有主流浏览器都支持
title
。但是您无法显示这种自定义工具提示: http://www.dreamcss.com/2009/03/list-of-25-javascriptajax-css-tooltip.html您是否见过用户将卡片悬停在 SO 上(此 地点)?如果他们使用了标题,那么可能无法显示如此精彩的工具提示。
All major browsers supports
title
. But then you don't have ability to show this kind of custom tooltips: http://www.dreamcss.com/2009/03/list-of-25-javascriptajax-css-tooltip.htmlHave you seen Users hover card on SO (this site)? If they have used title then it might be not possible to show such a wonderful tooltip.
所有主流浏览器确实都支持工具提示,因此请随意使用它们的 title 属性。我要提醒您的是,您还提供了一个 alt 属性来镜像标题,以实现可访问性(主要针对低视力和盲人用户)和容错(例如,如果图像无法加载或用户正在使用图像阻止用户)来自慢速连接的代理)。
All major browsers do indeed support tooltips, so feel free to use the title attribute for them. I would caution that you also provide an alt attribute to mirror the title for the sake of accessibility (mostly for low-vision and blind users) and fault tolerance (like if the image fails to load or the user is using an image-blocking user agent from a slow connection).
它的显示速度非常慢(Chrome 上为 1 或 2 秒),我怀疑现代互联网用户是否有那么大的耐心等待它的显示。
您可以使用第三方插件或使用 jQuery 的“mouseenter”和“mouseleave”事件自行对其进行硬编码(我大部分时间都是这样做的)。虚拟代码如下:
html:
JavaScript/jQuery:
It's really slow to show up(1s or 2 on Chrome) and I doubt modern internet users have that much patience waiting for it to show.
You could use third party plugins or hard code it yourself(what I do most of the time) using jQuery's "mouseenter" and "mouseleave" events. Dummy code as below:
html:
JavaScript/jQuery:
使用移动浏览器时要小心。那里大多不支持它。
Be careful when it comes to mobile browsers. It mostly isn't supported there.