MVC 解决 readonly 问题



<input type="text" class="form-control" name="UR_UserName" value="@Model.UR_UserName" readonly="readonly" />

修改用户名使用 readonly

 
新增的时候我们不需要。
在List页面,添加操作的时候,第1次打开 form 与 多次 都需要判断

//添加
    $('#mytool').on('click''button#addModel'function () {
        //加载页面基本信息
        $.ajax({
            url"/AdminUser/AdminUserForm",
            type"post",
            //参数:(html5:MenuForm页面html数据)
            successfunction (html5) {
                //只有在没赋值的情况下,才创建
                if ($("#createModal").html() == "") {
                    $("#createModal").html(html5);
                    $('input[name=UR_UserName]').removeAttr('readonly'); //-------因为form直接设置的 readyonly属性,所以第1次打开添加按钮时,移除用户的 readonly
                    //弹出框show
                    $("#myModal").modal("show");
                } else { 
                    //点“添加”,清除掉进度条
                    $('#uploadify-queue').html('');
                    //重置添加 modal 里面的 input 的值为 null
                    $("#formMenu input[type='text']").val('');
                    //移除禁修改 disabled 的插件
                    $("#formMenu input[type='text']").removeAttr('disabled');
                    //移除 checkbox
                    $("#formMenu input[type='checkbox']").removeAttr('checked');
                    //让select 选择 +<option selected="selected" value="-1">请选择一项数据!</option>
                    $("#formMenu select").val('-1');
                    //-----因为打开过修改窗口等,所以要判断下【用户名】是否加载了readonly
                    var attr = $("input[name=UR_UserName]").attr("readonly");
                    if (typeof attr !== typeof undefined && attr !== false) {
                        $('input[name=UR_UserName]').removeAttr('readonly');
                    }
                }
                //重置添加 modal 里面的 img 的值为 默认图片
                $('#showImage').attr('src''/UpLoad/image.png').attr('style''width:200px;height:150px');
            }
        });
    })


 





posted @ 2017-01-06 09:55  【唐】三三  阅读(997)  评论(0编辑  收藏  举报