// js的数组和对象 循环
function jsArrayObject(num) {
str = '{"姓名":"小明","性别":"男","身高":"163cm"}';
str2 = '["小明","男","163cm"]';
optionObj = (new Function("", "return " + str))();
console.log(optionObj)
console.log(typeof optionObj)
console.log(optionObj.length)
for(let key in optionObj){
console.log(key + ' => ' + optionObj[key])
}
optionObj2 = eval(str2);
console.log(optionObj2)
console.log(typeof optionObj2)
console.log(optionObj2.length)
for (var i = 0; i < optionObj2.length; i++) {
console.log(optionObj2[i]);
}
return
}
// 公共函数 类似于php的isset
function isset(obj) {
return !(typeof(obj) == "undefined") && (obj !== null)
}
function empty(obj) {
return (obj === "") || (obj === []) || (obj === {})
}
// ajax
$.ajax({
type: "POST",
url: "show",
data: {"id":1},
dataType: "json",
success: function (data) {
if (data.code == 1) {
layer.msg('操作成功');
var index = parent.layer.getFrameIndex(window.name);
setTimeout(function() {
parent.location.reload();
parent.layer.close(index);
}, 1000);
} else {
if (!data.msg) {
data.msg = '操作失败';
}
top.layer.msg(data.msg);
}
}
});