jquery - jQuery 是否真的使用 camelcaps 来引用多词 css 字段?

标签 jquery css

在 jQuery 中,多词 css 字段是否被压缩为 camelCaps?例如。

$("#item").css("marginBottom"); 

不是

$("#item").css("margin-bottom"); 

在我运行 Firefox 3.6.6 和 jQuery JavaScript Library v1.4.2 的机器上,答案似乎是否定的。做 $("#item").css("marginBottom"); 给我一个关于无效 css 字段的警告,并且声明已被删除。

最佳答案

实际上我错了——它在内部似乎是驼峰式的。下面是一段获取边距底部的代码(在 Fx 3.6 中测试):

el = document.body;
$('el').css('margin-bottom', '20px')
computed = document.defaultView.getComputedStyle( el, null )

computed['marginBottom'] // 0px

更新:这是来自 jQuery 的驼峰式然后小写代码:

x = 'marginBottom'.replace( /([A-Z])/g, '-$1').toLowerCase()

关于jquery - jQuery 是否真的使用 camelcaps 来引用多词 css 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3242514/

相关文章:

javascript - 通过 jquery 从 html 变量中获取特定标签

javascript - 如何使用 .animate() 显示隐藏文本?

html - 如何使用 Bootstrap 垂直对齐表单?

html - 背景不覆盖可滚动区域

javascript - 如何检测滚动值是否大于窗口高度?

javascript - 如何检测在 javascript 中按下 x 秒的键?

javascript - 访问 AngularJS 中的嵌套多维数组

jquery - 从 style 属性获取 font-size 属性

jQueryUI - AJAX 加载后调整对话框大小

html - IE 7 问题 : Super simple page - TD height not taking effect