我已经用 ajax 结果数据绑定了一个 div。绑定内容后它不起作用。在页面加载视图功能时,控件正在工作。但是在使用 ajax 将代码添加到 div 之后,当在填充的 div 中使用任何控件时,没有脚本运行。div 之外的控件正在使用脚本。
我正在使用 mvc 2,请帮助我。
ajax代码
function Operation(ActionResult, mod,discid) {
$.ajax({
type: 'Get',
url: ActionResult,
data: { strDiscId: discid, PageNum: $("#hdnPagenum").val(), PageCount: $("#hdnPageCount").val(),
strSearchType: $("#hidSort").val(),strSearchText: $("#hidSearchText").val() },
success: function (data) {
flag = true;
if (mod == "view") {
$("#taBody").val(data);
}
else {
$("#divContactsChecks").html(data);
}
}
});
}
});
$("#liTitle").click(function () {
$("#hidSort").val('TS'); //Title Sort
Operation('LoadDisclaimers', 'Load',0);
});
服务器端代码
public string LoadDisclaimers(string strDiscId, string PageNum, string PageCount,string, strSearchType,string strSearchText)
{
string strTable = "";
AdminModel objModel = new AdminModel();
DataTable dtDisc = new DataTable();
string strOrderBy = "";
switch (strSearchType)
{
case "TS": strOrderBy = "[name]"; break;
case "US": strOrderBy = "date_updated"; break;
case "CS": strOrderBy = "date_created"; break;
case "TSD": strOrderBy = "[name] desc"; break;
case "USD": strOrderBy = "date_updated desc"; break;
case "CSD": strOrderBy = "date_created desc"; break;
default: strOrderBy = "[name]"; break;
}
using (dtDisc = objModel.GetDisclaimer(strOrderBy, Convert.ToInt16(PageNum), Convert.ToInt16(PageCount), strSearchText))
{
for (int i = 0; i < dtDisc.Rows.Count; i++)
{
string strId = dtDisc.Rows[i]["disc_id"].ToString();
strTable += "<div class='border-bottom-line gm-pad-tb-12'>";
strTable += "<span class='display-ib-top'><input id='ipCheck" + strId + "' type='checkbox' value='" + strId + "' class='default-checkbox' />";
strTable += "<label for='ipCheck" + strId + "'></label></span>";
strTable += "<div class='display-ib-top m-left25 span-45-p'>";
strTable += "<div><span id=spTitle_" + strId + " class='blue-h1 font-arial-18'>" + dtDisc.Rows[i]["name"].ToString() + "</span></div>";
strTable += "<div><span class='font-arial-14 display-ib-middle'>Created on : </span>";
strTable += "<span class='display-ib-middle adm-disable font-arial-12'>" + dtDisc.Rows[i]["date_created"].ToString() + "</span></div>";
strTable += "<div><span class='font-arial-14 display-ib-middle'>Modified on : </span>";
strTable += "<span class='display-ib-middle adm-disable font-arial-12'>" + dtDisc.Rows[i]["date_updated"].ToString() + "</span></div>";
strTable += "</div><div class='display-ib-middle rgt'>";
strTable += "<span id=spViewDisc_" + strId + " class='display-ib-middle light-grey-btn large-btn'>View Details</span></div></div>";
}
}
ViewData["Disclaimers"] = strTable;
return strTable;
}