JQuery 或条件 CSS?
我在很多空间中执行此操作,因此只想检查在这种情况下最佳实践是什么
if(ElementIsToBeShown)//This is java server side statement
.Options{
Display:block;
}else{ //ServerSide
.Options{
Display:none;
}
}
,或者使用 JQuery.show 和 hide 来执行此操作?
I do this thing at lot of space so just want to check on what will be best practice in this case
if(ElementIsToBeShown)//This is java server side statement
.Options{
Display:block;
}else{ //ServerSide
.Options{
Display:none;
}
}
Or use JQuery.show and hide to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
服务器端总是更好,因为它会立即工作,即使 JavaScript 被关闭。
你展示的方法很好。
如果这是要全局隐藏某种类型的元素,另一种选择是为
body
标记指定一个特定的类名:(这是伪代码;你知道我的意思)
并让 CSS 包含该规则如果主体具有该类,则隐藏该类的所有元素
.Options
:这很好,因为您可以将其硬编码到 CSS 中,并且只需要更改主体的类。但正如所说,你展示的方法也很好。
Server side is always better, because it'll work immediately, and even if JavaScript is turned off.
The method you show is fine.
If this is to globally hide a certain type of elements, another option is giving the
body
tag a specific classname:(this is pseudo-code; you know what I mean)
and having the CSS contain the rule that if the body has that class, hide all elements of the class
.Options
:this is nice because you can hard-code this into your CSS, and need to alter the body's class only. But as said, the method you show is fine as well.