我创建了一个带有搜索文本框的网站,用于使用Jquery和JSON搜索Gridview内容,但是当我键入阿拉伯字母时,它什么也不显示。似乎一定有 正则表达式的问题。我使用了一个名为persianRex的库来解决此问题,但是网站弹出了警报,提示未定义。
这是我的代码
<script type="text/javascript" charset="utf-8">
$(function () {
GetPatients(1);
});
$("[id*=txtSearch]").live("keyup", function () {
GetPatients(parseInt(1));
});
$(".Pager .page").live("click", function () {
GetPatients(parseInt($(this).attr('page')));
});
function SearchTerm() {
return jQuery.trim($("[id*=txtSearch]").val());
};
function GetPatients(pageIndex) {
$.ajax({
type: "POST",
url: "Main.aspx/GetPatients",
data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
var row;
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var patients = xml.find("PatientInfo");
if (row == null) {
row = $("[id*=gvPatients] tr:last-child").clone(true);
}
$("[id*=gvPatients] tr").not($("[id*=gvPatients] tr:first-child")).remove();
if (patients.length > 0) {
$.each(patients, function () {
var patient = $(this);
$("td", row).eq(0).html($(this).find("PatientFName").text());
$("td", row).eq(1).html($(this).find("PatientLName").text());
$("td", row).eq(2).html($(this).find("PatientFAName").text());
$("td", row).eq(3).html($(this).find("PatientNC").text());
$("td", row).eq(4).html($(this).find("PatientAddress").text());
$("td", row).eq(5).html($(this).find("PatientMobile").text());
$("td", row).eq(6).html($(this).find("VisitDate").text());
$("td", row).eq(7).html($(this).find("VisitReason").text());
$("td", row).eq(8).html($(this).find("Price").text());
$("[id*=gvPatients]").append(row);
row = $("[id*=gvPatients] tr:last-child").clone(true);
});
var pager = xml.find("Pager");
$(".Pager").ASPSnippets_Pager({
ActiveCssClass: "current",
PagerCssClass: "pager",
PageIndex: parseInt(pager.find("PageIndex").text()),
PageSize: parseInt(pager.find("PageSize").text()),
RecordCount: parseInt(pager.find("RecordCount").text())
});
$(".PatientFName").each(function () {
var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "<span style = 'background-color:red;color:white;'>" + SearchTerm() + "</span>"));
});
$(".PatientLName").each(function () {
var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "<span style = 'background-color:red;color:white;'>" + SearchTerm() + "</span>"));
});
$(".PatientFName + ' ' + .PatientLName").each(function () {
var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "<span style = 'background-color:red;color:white;'>" + SearchTerm() + "</span>"));
});
}
else {
var empty_row = row.clone(true);
$("td:first-child", empty_row).attr("colspan", $("td", row).length);
$("td:first-child", empty_row).attr("align", "right");
$("td:first-child", empty_row).attr("color", "red");
$("td:first-child", empty_row).attr("font-family", "B Titr");
$("td:first-child", empty_row).html("No Records Found.");
$("td", empty_row).not($("td:first-child", empty_row)).remove();
$("[id*=gvPatients]").append(empty_row);
}
};
</script>
预先感谢