为什么 Bootstrap 使用 Javascript 而不是纯 CSS? [英] Why Bootstrap use Javascript instead pure CSS?

查看:30
本文介绍了为什么 Bootstrap 使用 Javascript 而不是纯 CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Bootstrap 3 的新手,但我注意到 Bootstrap 需要 Javascript,即使它不是必需的,例如如果 js 被禁用,下拉菜单不起作用.有什么理由更喜欢 js 而不是 CSS 吗?

I'm newbie to Bootstrap 3, but I noticed that Bootstrap require Javascript even if it's not necessary, e.g. dropbown menu doesn't work if js is disabled. Is there any good reason to prefer js over CSS?

推荐答案

我认为是因为 Javascript 和 CSS 是不同的,不能相互替代.在 CSS 中,你不能做例如计算、DOM 操作、对点击和其他实时事件的反应.Javascript 无法设置 HTML 样式,进行媒体查询等.另请参阅:性能:纯 CSS 与 jQuery

I think cause Javascript and CSS are different and can't replace each other. In CSS you can't do for example calculations, DOM manipulation, react on click and other live events. Javascript can't style your HTML, have media queries etc. see also: Performance: Pure CSS vs jQuery

是的,我知道一切都有替代方案,请参阅:

Yes, i know there are alternative for everything, see:

我可以在纯 CSS 中执行此操作吗而不是使用 jQuery?我可以在 CSS 中使用点击效果吗?等....但它不一样.

Can I do this in pure CSS instead of using jQuery?, Can I have an onclick effect in CSS?, etc .... but it is not the same.

您的 JavaScript 有什么问题?首先?您是否有一些要求,例如:应该在禁用 javascript 的情况下工作".您的网站应该符合此要求还是完全相同.禁用 javascript 的替代方法是什么?基本的CSS?完整的CSS3?对我来说,在禁用 javascript 的情况下防止错误似乎是现实的,但不要期望所有的工作都一样.如果是下拉菜单,您可以考虑替代导航结构.

What's your problem with javascript? in the first place? Do you have some requirements like: "should work with javascript disabled". Should your site work with this requirement or should it be exactly the same. What are you alternatives for javascript disabled? basic CSS? full css3? For me it seems realistic to prevent errors with javascript disabled but not expect all work the same. In the case of a dropdown you could consider a alternative navigation structure.

这篇关于为什么 Bootstrap 使用 Javascript 而不是纯 CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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