本文共 1551 字,大约阅读时间需要 5 分钟。
正常情况:
JSON解析错误: 改正后的代码:$("#getdata").on("click",function() { getdata(); }); $("tbody").on("click", ".getid", function() { var jsonstr = decodeURIComponent($(this).parent().parent().parent().attr("dataentity")); var selectedEntity = JSON.parse(jsonstr); alert("id:" + selectedEntity.ID); }); function getdata(parameters) { $.ajax({ type: 'POST', url: "Controller/Handler1.ashx", async: true, data: "function=theFunction" , dataType: 'json', success: function(jsonObj) { if (jsonObj.success) { $("tbody").empty(); for (var i = 0; i < jsonObj.data.length; i++) { var button = ""; $("" + "" +jsonObj.data[i].ID + "" + "" + jsonObj.data[i].col1 + "" + "" + jsonObj.data[i].col1 + "" + "" + button + "" +"").appendTo($("tbody")); } } else { window.alert(jsonObj.msg); } } }); }
改正后的结果:
转载地址:http://pxtwn.baihongyu.com/