前台的js:
function changeColor(rankid, changetorest, rowIdx) {
$.ajax({
type: "Post",
url: "OvertimeBatchFormFrm_Crcement.aspx/CheckColor_Blur",///页面地址,以及后台的方法名称
data: "{'rankid':'" + rankid + "','changetorest':'" + changetorest + "'}",//向后台传递的参数
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var bcolor = data.d;///取得后台的返回值
highlightRows(rowIdx, bcolor);
},
error: function (err) {
F.alert(err);
}
});
}
后台的方法
OvertimeBatchFormFrm_Crcement.cs
[WebMethod] ///注意WebMethod标签
public static string CheckColor_Blur(string rankid, string changetorest)///注意是要用public static
{
string result = "1";
try
{
char[] chararray = new char[] { '_' };
if (changetorest == "0")
{
string[] rankarray = rankid.Split(chararray);
if (rankarray.Length > 0)
{
string rank = rankarray[0];
string rank1 = rank.Substring(0, 1);
int rank2 = int.Parse(rank.Substring(1, 1));
if (rank1 == "M")
{
if (rank2 >= 3)
{
result = "0";
}
}
else if (rank1 == "P")
{
if (rank2 >= 4)
{
result = "0";
}
}
}
}
}
catch
{
result = "1";
}
return result;
}