嵌套if语句vs&&操作员javascript jquery
nested if statement vs && operator javascript jquery
我一直在使用&;运算符,其中一个嵌套语句以旧形式工作,但一旦转换就停止工作。
我做错了吗?
考虑:
;(function( $, window ){
var jsonData = <venda_block></venda_block>,
isActive = jsonData.isActive, // false = off, true = on
spendThreshold = jsonData.spendThreshold,
displayThreshold = jsonData.displayThreshold,
orderTotal = <venda_total>,
remainingSpend = spendThreshold - orderTotal;
$('.deliveryType').text(jsonData.deliveryType);
if (isActive) {
if (orderTotal >= displayThreshold) {
if (!(orderTotal >= spendThreshold)) {
$('.freeDeliveryBlurb2').show();
$('.remainingSpend').html(remainingSpend);
}}}
}( jQuery, window ));
&;
if (isActive) {
if (orderTotal >= displayThreshold && !(orderTotal >= spendThreshold)) {
$('.freeDeliveryBlurb2').show();
$('.remainingSpend').html(remainingSpend);
}}
}( jQuery, window ));
如果您想用&;:
if (isActive) {
if (orderTotal >= displayThreshold) {
if (!(orderTotal >= spendThreshold)) {
$('.freeDeliveryBlurb2').show();
$('.remainingSpend').html(remainingSpend);
}}}
结果可能是这样的:
if (isActive && orderTotal >= displayThreshold && !(orderTotal >= spendThreshold)) {
$('.freeDeliveryBlurb2').show();
$('.remainingSpend').html(remainingSpend);
}
或者,作为!(orderTotal>=spentThreshold)相当于(orderTotal<spentThrecture),如下所示:
if (isActive && orderTotal >= displayThreshold && orderTotal < spendThreshold) {
$('.freeDeliveryBlurb2').show();
$('.remainingSpend').html(remainingSpend);
}
请注意,如果语句写错了,您的原始代码中可能存在如下错误:
if (orderTotal >= displayThreshold {
而不是
if (orderTotal >= displayThreshold) {
相关文章:
- jquery点击函数select&取消选择
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- Angular js-返回一个包含类似
- 一点javascript元编程&可链接的设置器
- 操作员”;新的“;根据我想在几个JavaScript文件中使用的类,在JavaScript中使用
- 通过JSON&比较时间
- Jquery模板,如果xx&&如果yy
- jQuery工具验证器自定义效果-添加&消除影响
- Twitter引导程序Typeahead-Id&标签
- AngularJS&JSON-从Previous&下一个对象
- 什么是&&在没有if的行中的变量之间
- 关于引入外部javascript文件的问题&css通过https
- 指令的模板必须只有一个根元素:With restrict E&替换true
- 使用ajax的服务器端分页&jQuery
- Javascript,如果条件在没有&&逻辑运算符当&&它不起作用
- 如何使用dropzone&vueJs
- 如何准确执行加载脚本&退出弹出窗口
- 嵌套if语句vs&&操作员javascript jquery
- &操作员未在指令的隔离范围内工作
- Javascript if语句和&&操作员差异