在“生产”代码中不推荐使用jQuery .css [英] jQuery .css not recommended in 'production' code

查看:162
本文介绍了在“生产”代码中不推荐使用jQuery .css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery 文档提供了一个注释'
它不是建议在生产就绪代码中使用.css()作为设置器,但是当传递一个对象来设置CSS时,CSS属性将是camelCase而不是连字符。'



a)为什么不建议在生产就绪代码中使用?



b)但是当传入一个对象来设置CSS时,CSS属性



所以jQuery会在内部修改font-family到fontFamily,或者这只是一个建议吗?

有没有经验丰富的程序员可以进一步澄清这一点?

解决方案

$



样式的CSS类



作为getter,.css()方法是有价值的。然而,它应该
一般避免作为生产就绪代码中的setter,因为
通常最好保持表示信息从
JavaScript代码。相反,为描述
的类编写CSS规则以处理各种视觉状态,然后更改元素上的类。



The jQuery documentation makes a remark, ' It's not recommended to use .css() as a setter in production-ready code, but when passing in an object to set CSS, CSS properties will be camelCased instead of using a hyphen.'

a) Why is it not recommended to use this in production-ready code?

b) "but when passing in an object to set CSS, CSS properties will be camelCased instead of using a hyphen."

So jQuery will modify "font-family" to "fontFamily" internally, or is this just a suggestion made here?

Are there any experienced programmers that can further clarify this?

解决方案

Your answer to point a is found on the same page you linked to:

Using CSS Classes for Styling

As a getter, the .css() method is valuable. However, it should generally be avoided as a setter in production-ready code, because it's generally best to keep presentational information out of JavaScript code. Instead, write CSS rules for classes that describe the various visual states, and then change the class on the element.

这篇关于在“生产”代码中不推荐使用jQuery .css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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