由于我对逻辑的不清晰,以及从来没有系统学过javascript ,所以在写jQuery的时候常常写得比较长。比如,对于判断来说,我经常的写法如下:
if (i==0) {
$(this).hide();
};
或者,我还会这么写:
if (i==0) {
$(this).hide();
} else{
$(this).show();
};
当然,这么写不能算错。但是使用三目运算来写的话呢,就会简洁得多。比如第一个,可以这样来写:
if (i==0) ? $(this).hide() : null ;
而第二个,则可以这样来写
if (i==0) ? $(this).hide() : $(this).show();
这样写就简单舒服得多了。
不过我对三目运算的运用还真是不熟练,在以后的工作中一定要多练习。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有