js獲取PHP傳過來的值如果為空或者為null或者為undefined
阿新 • • 發佈:2018-11-26
如果不設定js的值
那麼編輯時頁面會出現 可能是 null 或者undefined
var swd_id = $(t).attr("id-data"); //商品id SWD_ID = swd_id; var a_price = $(t).attr("aprice-data"); //渠道價 var c_price = $(t).attr("cprice-data"); //修理廠價 var cost_price = $(t).attr("cost-data"); //修理廠價 var w_name = $(t).attr("wname-data"); //商品名稱 var oe = $(t).attr("oe-data"); //oe var description = $(t).attr("description-data"); //車型備註 var mcode = $(t).attr("mcode-data"); //mcode 助記碼 var rem = $(t).attr("rem-data"); //備註 if(oe == "" || oe=== "undefined" || oe === "null"){ var oe=""; } if(description == "" || description === "undefined" || description === "null"){ var description=""; } if(rem == "" || rem=== "undefined" || rem === "null"){ var rem =""; } if(mcode == "" || mcode=== "undefined" || mcode === "null"){ var mcode=""; } $("#costprice").val(cost_price); $("#aprice").val(a_price); $("#cprice").val(c_price); $("#wname").val(w_name); $("#oe").val(oe); $("#description").val(description); $("#rem").val(rem); $("#mcode").val(mcode);
當時 oe== undefined || oe == null 就一直出現頁面的null 或者是undefined
這裡一定要使用 全等於 的