function getNewId(nums,jsonObject){ var fp_hm = jsonObject.FP_DM; if (nums fp_hm.length) { console.log("输入长度大于字符串长度,程序中止"); return null; } var sub_fp_hm = fp_hm.substr(fp_hm.length - nums); return getNewStr(s
function getNewId(nums,jsonObject){ var fp_hm = jsonObject.FP_DM; if (nums > fp_hm.length) { console.log("输入长度大于字符串长度,程序中止"); return null; } var sub_fp_hm = fp_hm.substr(fp_hm.length - nums); return getNewStr(sub_fp_hm); } function getNewStr(oldStr){ var newStr = ""; for(var i = oldStr.length - 1; i >= 0; i--){ newStr += oldStr[i]; } return newStr; } var newJson = new Object(); newJson.FP_HM = "123456789"; newJson.FP_DM = "18312711538"; var json = eval(newJson); var result = getNewId(11, json); console.log(result);