后端返回数据前端判断 : (data.prizeName==null) js中直接判断即可
前端定义变量判断方法 var tmp = null; if (!tmp && typeof(tmp)!=”undefined” && tmp!=0){ alert(“null”);}
前端判断!坑 if(! “a”==”b” ) 先对a取反几位false vs if(! ( “a”==”b”) ) 对结果取反
java中判断结果是一样的,这点和js不同 if(! “a”.eqals(“b”)) if(! (“a”.eqals(“b”)))
=====================================================================================
var _list = [];
var freightSingle = {};
freightSingle.serviceType =1;
freightSingle.gcId = 2;
//配置的值
freightSingle.expeFreight = $("#expenseForm").find("input[name='expeFreight']").val();
//ftl判断导致页面元素不存在
var expetaxValue = $("#expenseForm").find("input[name='expeAddedtax']").val();
freightSingle.expeAddedtax = (expetaxValue===undefined)?"0":expetaxValue;
freightSingle.isEffect=0;
console.log(freightSingle)
_list.push(freightSingle);
console.log(JSON.stringify(_list))
{serviceType: 1, gcId: 2, expeFreight: undefined, expeAddedtax: "0", isEffect: 0}
//JSON.stringify(_list)导致expeFreight 字段值丢失
[{"serviceType":1,"gcId":2,"expeAddedtax":"0","isEffect":0}]
版权声明:本文为qq_31459039原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。