4
我不知道如何搜索这个,所以我在这里问。Javascript和jQuery语法
我试图找出这个代码是如何工作的:
if ($("#main .oc .dc .image").removeAttr("style"), 1120 > wW && wW > 920)
$("#main .oc .dc .image").css({
width: Math.round(.3 * wW) + "px",
left: "calc(50% - " + Math.round(.3 * wW/4) + "px)"
});
我的问题是 -
是什么.removeAttr("style")
和1120 > wW
之间的逗号在这个语句的条件呢?
,这也正是行动执行后, -
$("#main .oc .dc .image").css(
图支架以及缺乏行情的之前,CSS属性 -
{width:Math.round(.3*wW)+"px",left:"calc(50% - "+Math.round(.3*wW/4)+"px)"}
混淆了我。
我认为这是一个技巧,逗号运算符将右手表达式返回给'if'语句 – adeneo
@adeneo true - 只有在提供逗号分隔时才检查最后一个条件:https://jsfiddle.net/bgav45wm /。尽管 –
@RoryMcCrossan,但我仍然认为它是不好的做法 - 当然,没有理由以这种方式去除那个属性,它可以在if条件之前放在它自己的行上,有人只是“聪明” 。 – adeneo