前台代码:
var test = "";
function selectBtn_onclick() {
var ids = ""; //存储选中的复选框的ID集合
var text = ""; //存储将选中的复选框所代表的数据 Table化 的纯HTML代码
var check = document.getElementsByTagName("input");
for (var i = 0; i < check.length; i++) {
if (check[i].checked) {
ids += check[i].defaultValue + ",";
}
}
if (ids != "") {
ids = ids.substr(0, ids.length - 1);
$.ajax({
type: "POST",
url: "ShowEquipInfo.aspx/GetHtmlTable",
data: { ids: ids },
dataType: "json",
async: false,
success: function (json) {
test = json;//这个位置怎么写代码啊?总是接收不到json的值
}
});
} else {
alert("请选择至少一个设备...");
}
alert(test);
}
后台代码:
[WebMethod]
public static string GetHtmlTable(string ids) {
StringBuilder strbui = new StringBuilder();
strbui.Append("<table>");
strbui.Append("<tr><td>设备编号</td><td>电压等级编号</td><td>厂家编号</td><td>类型编号</td><td>区域编号</td><td>设备编码</td>");
strbui.Append("<td>检验日期</td><td>存放位置</td><td>设备状态</td><td>备注</td><td>排序</td><td>是否删除</td></tr>");
List<string> lists = ids.Split(',').ToList<string>();
foreach (string ss in lists) {
EquipInfoEntity equip = DAL<EquipInfoEntity>.GetEntityById(ss);
if (equip != null) {
strbui.Append("<tr>");
strbui.Append("<td>" + equip.Equip_ID + "</td><td>" + equip.Lev_ID + "</td><td>" + equip.Sup_ID + "</td>");
strbui.Append("<td>" + equip.Type_ID + "</td><td>" + equip.Part_ID + "</td><td>" + equip.Equip_Code + "</td>");
strbui.Append("<td>" + equip.Equip_Date + "</td><td>" + equip.Equip_Adr + "</td><td>" + equip.Equip_State + "</td>");
strbui.Append("<td>" + equip.Equip_Remark + "</td><td>" + equip.Sorting + "</td><td>" + equip.IsDel + "</td>");
strbui.Append("</tr>");
}
}
strbui.Append("</table>");
return strbui.ToString();
}