jquery更改Reaper某一列的值

时间:2025-01-21 16:34:26

一、实现效果:通过Jquery实现点击repeater中的按钮循环修改快递专线的线路状态

1、初始效果图

jquery更改Reaper某一列的值

2、点击关闭专线按钮之后的效果图

jquery更改Reaper某一列的值

二、MVC模式实现上述效果

SQLServerDAL层

        #region 修改快递线路状态
/// <summary>
///根据自动编号、快递线路状态修改快递线路信息
/// </summary>
/// <param name="Id">自动编号</param>
/// <param name="IsSpecial">是否专线</param>
/// <returns></returns>
public int UpdateSpecial(int Id, bool IsSpecial)
{
string str = string.Format("update ExpressLine set IsSpecial={0} where Id={1}", Convert.ToInt32(IsSpecial), Id);
return DBUtility.SqlHelper.ExecuteNonQuery(ConnString.conn, CommandType.Text, str, null);
}
#endregion

Models层——>DAL层

        #region 修改专线状态
/// <summary>
///根据自动编号、专线状态修改快递线路信息
/// </summary>
/// <param name="Id">自动编号</param>
/// <param name="IsSpecial">专线状态</param>
/// <returns></returns>
public static int UpdateSpecial(int Id, bool IsSpecial)
{
return new SQLServerDAL.ExpressLine().UpdateSpecial(Id, IsSpecial);
}
#endregion

Controllers层

        /// <summary>
/// 修改专线状态
/// </summary>
/// <param name="id">自动编号</param>
/// <param name="special">是否开通专线</param>
/// <returns></returns>
public JsonResult UpdateSpecial(int id, bool special)
{
special = special == true ? false : true;
if (Models.DAL.ExpressLine.UpdateSpecial(id, special) > )
{
return Json(new { code = , msg = "" });
}
else
{
return Json(new { code = 0, msg = "修改失败" });
}
}

Views层

@model IEnumerable<Wutong.Model.MiniExpressLine>
@{
ViewBag.Title = "会员中心-快递线路管理";
}
<form>
<table width="720" class="tb2" cellpadding="0" cellspacing="0">
<tr>
<td class="dh strong" width="40"><input type="checkbox"></td>
<td class="dh strong" width="150">出发地->到达地</td>
<td class="dh strong" width="100"> 发布/刷新时间</td>
<td class="dh strong" width="50">线路状态</td>
<td class="dh strong" width="50">管理线路</td><td class="dh strong" width="30">查看</td>
<td class="dh strong" width="30">修改</td>
<td class="dh strong" width="30">删除</td>
</tr>
@foreach (var item in Model)
{
<tr data="@item.Id" data1="@item.IsSpecial">
<td width="40"><input type="checkbox"></td>
<td style="line-height: 15px;">@item.StartArea -> @item.ArriveArea</td>
<td style="line-height: 15px;">@item.AddDate</td>
<td style="line-height: 15px;">@((item.IsSpecial) == true ? "专线" : "非专线")</td>
<td><input type="button" value='@((item.IsSpecial) == true ?"关闭专线" : "开通专线")' class="btnUpdateSpecial"></td><td><a href="/ExpressLineInfo/@item.Id"><img src="/images/find.png" width="19" height="19"></a></td>
<td><a href="/Member/PublishExpressLine/?type=get&id=@item.Id"><img src="/images/xg.png" width="16" height="16"></a></td>
<td><a href="javascript:void" class="del"><img src="/images/del.png" width="19" height="19" title="删除"></a></td>
</tr>
}
</table>
</form>
@section Js{
<script type="text/javascript">
$(function () {
$(".btnUpdateSpecial").click(function () {
var $parent = $(this).parent().parent();
var _id = $parent.attr("data");
var _special = $parent.attr("data1");
$.post("/Member/UpdateSpecial/", { id: _id, special: _special }, function (json) {
if (json.code == 1) {
//修改线路状态成功,刷新当前页面,改变按钮显示的值
location = location;
return true;
}
else {
//修改线路状态失败
alert(json.msg);
return false;
}
});
//更改线路状态
$parent.each(function () {
$parent.find("td:eq(3)").each(function () {
if ($(this).html() == "非专线") {
$(this).html("专线");
}
else {
$(this).html("非专线");
}
});
}); });
});
</script>
}