问题描述
因为我喜欢将所有源代码保存在一个文件中(每个类),所以我决定使用JQuery对象添加所有样式和CSS,即:
Because I like keeping all source code in one file (per class), I decided to add all style and CSS using JQuery objects, i.e:
jquery : $('<div/>',
{
id:'Object',
css:{
height:'100%',
width:'69%',
color:'white',
fontWeight:'bold',
textAlign:'center',
backgroundColor:'#02297f',
marginLeft:'.5%',
'float':'left',
overflow:'auto',
borderRadius:'5px'
},
html : 'My JQuery Object'
}),
现在我知道可能会对性能产生某种影响,但是我的问题是多少?还有其他人这样做吗?我是否忽略了潜在的问题?
Now I know there is probably going to be some sort of performance impact, but my question is how much? Does anyone else do it this way? Am I overlooking a potential problem?
之所以喜欢这种方式,是因为我可以只使用对象,而不必交叉检查样式表,这样可以使样式表井井有条.
I like it this way because I can just use objects rather than having to cross examine a stylesheet and it keeps it better organized.
这是针对Javascript应用程序的,而不是针对网页的.因此,禁用Javascript仍然会杀死该网页.
This is for a Javascript application, not a web page. So disabling the Javascript will kill the webpage anyway.
推荐答案
肯定会对性能产生影响.该脚本仅在加载了所有页面后才运行,因此在首次显示该页面时会给您带来问题.
There is certainly a performance impact. The script is only run when all the page is loaded, so it will give you problems when the page is first displayed.
除此之外,当您运行禁用了javascript的浏览器时,根本没有样式.
Apart from that, you got no styling at all when you run a browser where javascript is disabled.
但是最重要的是,这是一个坏主意. CSS是用于样式的,用于页面的外观. HTML用于结构,而Javascript用于逻辑,交互性.我认为您根本不应该使用.css方法.如果需要在Javascript中切换样式,请改用类,然后可以使用样式表设置样式.
But most of all, it is a Bad Idea. CSS is for styling, for the looks of your page. HTML is for structure, and Javascript is for logic, interactivity. I think you shouldn't use the .css method at all. If you need to toggle styles in Javascript, use classes instead, which can then be styled using style sheets.
但是您的这种方法甚至更进一步.我认为这比将所有css置于内联样式属性中还要糟糕.我希望您只是在问这个问题,以了解人们的反应.一定不是认真的. :s
But this method of yours takes it a step further even. I think it's even worse than putting all the css in inline style attributes. I hope you are just asking this question to see how people respond. It must not be serious. :s
这篇关于对CSS和样式表使用JQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!