jquery+ashx checkbox 单选判断是否true 和 false 传值操作

示例图:

html标签代码:

        <p></p>
        <label for="checkbox" style="float:left" >是否常用:</label>
        <input type="checkbox" name="ChkIsUse" id="ChkIsUse" value=""   style="width:10px" />
<
p></p>
jquery

//录入信息传递参数值时

$(function (){

tag = "add";

 var ischeck = $("#ChkIsUse").attr("checked") == "checked" ? 1 : 0;//是否常用 获取值 1常用

$.post('/ashx/Handler.ashx', { fun: 'save', tag: tag, ischeck: ischeck },

}

       //编辑修改
        function editInfo(guid) {
            tag = "edit";
           
            $("#dialog-form").dialog("open");
            $.post("/ashx/Handler.ashx", { fun: 'get', type: iType }, function (data, status) {
                $("#SelectNode").append(data);
            });
           
            $.post("/ashx/Handler.ashx", { fun: 'model', guid: guid }, function (data, status) {
                result = eval('(' + data + ')');
              
                strGuid = guid;
                $("#SelectNode").attr("value", result.ParentNode);
                $("#ChkIsUse").attr("checked",result.IsPopular==1);//取到值时为1项显示true 为0 则false IsPopular为数据表字段属性
      
            });
        }
Handler 一般处理程序文件Handler.ashx:

//获取传递值 是否常用

   string tag = context.Request.Form["tag"];
   string ischecked = context.Request.Form["ischeck"];

if (tag == "add") //添加
                    {
                        strBuilder.Append((addInfo( ischecked)));
                    }
                    else
                    {     //修改
                        string strguid = context.Request.Form["guid"];
                        if (editInfo( ischecked,strguid))
                              strBuilder.Append("success");
                          else
                              strBuilder.Append("error");
                    }
                    context.Response.Write(strBuilder);

//添加

private string addInfo( string ischecked)
        {
            Model.info model = new Model.info();        
            model.IsPopular = Convert.ToInt32(ispopular);//是否常用   

           //这里就是增加数据信息的操作方法了  省略
            if (bll.Add(model))
                return model.guid.ToString();
            else
                return "";
        }

//编辑修改信息

 private bool editInfo( string ischecked, string guid)
        {
            Model.info model = new Model.info();
            model = bll.GetModel(new Guid(guid));
           
            model.IsPopular = Convert.ToInt32(ispopular);//是否常用
            //这是修改信息操作 省略
            return bll.Update(model);
        }

 

 

 

posted @ 2014-02-26 14:37  蜜雪粮液  阅读(2037)  评论(0编辑  收藏  举报