美文网首页
2018-10-30jquery实际应用

2018-10-30jquery实际应用

作者: 小牛长成记 | 来源:发表于2018-10-30 15:36 被阅读0次
    $(function(){
        var b ;
        var depName = $("#depName");
        var sort = $("#sort");
        //检验修改后的部门名称是否存在
        $("#depName").blur(function(){
            if(depName.val()==""){
                 $("#msg").html("<font color='red'>部门名称不能为空!</font>");
                    $("#ssb").attr("disabled",true);
                    return false;
            }
            /* alert(depName.val()) */
            $.ajax({
                url : "${pageContext.request.contextPath}/DeptController?flag=checkDeptName&depName="+depName.val(),
                success:function(data){
                    if(data=="ok"){
                        $("#msg").html("<font color='red'>该部门已存在!</font>");
                        $("#ssb").attr("disabled",true);
                    }else{
                        $("#msg").html("<font color='green'>该部门可用</font>");
                        $("#ssb").attr("disabled",false);
                    }
                }
            });
        });
        //部门名称非空判断
        $("#ssb").click(function(){
            if(depName.val()==""){
                 $("#msg").html("<font color='red'>部门名称不能为空!</font>");
                    $("#ssb").attr("disabled",true);
                    return false;
            }
        });
        //排序非空判断
        $("#sort").blur(function(){
            if(sort.val()==""){
                 $("#msg").html("<font color='red'>请填入优先级!</font>");
                    $("#ssb").attr("disabled",true);
                    return false;
            }
        });
        //加载所有的部门信息
        $.ajax({
            url : "${pageContext.request.contextPath}/DeptController?flag=deptManage_ajax",
            type:"post",
            dataType : "json",
            success:function(data){
                d = data;
                var mytable = $("#mytable");
                var dataObj = eval(data);
                $.each(dataObj,function(key,val){
                    var id= val["id"];
                    var depName = val["depName"];
                    var depCreateTime = val["depCreateTime"];
                    var d = depCreateTime["time"]+"";
                    var sort = val["sort"];
                    var date = new Date(parseInt(d.replace("/Date(\",\"").replace(")/\",\""), 10));
                    var year = date.getFullYear();
                    var month = date.getMonth + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                    var hour = date.getHours();
                    var minute = date.getMinutes();
                    var second = date.getSeconds();
                    var datastr = year + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second;  
                    mytable.append("<tr><td>"+id+"</td><td>"+depName+"</td><td>"+datastr+"</td><td>"+sort+"</td><td id="+id+" class='td-actions text-right' width='80px'><button type='submit' rel='tooltip' uid="+id+" id='update' title='修改' class='btn btn-info btn-simple btn-xs' ><i class='fa fa-edit'></i></button><button type='button' rel='tooltip' title='删除'  id='del' did="+id+" value='23' class='btn btn-danger btn-simple btn-xs'  ><i class='fa fa-times'></i></button> </td></tr>");
                });
                
            }
        });
        //点击触发删除部门事件
        $("table").on("click","#del",function(){
            
            var a = $(this).attr("did");
            $.ajax({
                async : false,
                type:'post',
                dataType:'text',
                url : "${pageContext.request.contextPath}/DeptController?flag=checkPerson&depID="+$(this).attr("did") ,
                success:function(data){
                    if(data=="ok"){
                        alert("当前无法删除该部门!");
                        
                    }else{
                        $.ajax({
                            async : false,
                            type:'post',
                            dataType:'text',
                            url : "${pageContext.request.contextPath}/DeptController?flag=delDept&id="+a,
                            success:function(data){
                                if(data=="ok"){
                                    alert("已删除该部门!");
                                    window.location.href="${pageContext.request.contextPath}/admin/deptManage.jsp";
                                }
                            }
                        }); 
                    }
                }
            }); 
        });
        //点击触发显示修改部门信息弹窗
        $("table").on("click","#update",function(){
            var b = $(this).attr("uid");
            $("span2").show(1000,function(){
                $.each(d,function(key,val){
                    if(b==val["id"]){
                        $("#depName2").val(val["depName"]);
                        $("#sort2").val(val["sort"]);
                        $("#depid").val(val["id"]);
                    }
                    
                });
                 });
        });
        //点击触发隐藏修改部门弹窗
        $("table").on("click","#bttn",function(){
            $("span2").hide(1000,function(){
                   
                 });
        });
        //点击触发修改部门信息
        $("table").on("click","#change",function(){
            //alert($("#depName2").val()+$("#depid").val());
            $.ajax({
                url : "${pageContext.request.contextPath}/DeptController",
                data :{
                    flag : "updateDept",
                    id : $("#depid").val(),
                    depName : $("#depName2").val(),
                    sort : $("#sort2").val()
                },
                success:function(data){
                    if(data=="ok"){
                        alert("修改成功!");
                        window.location.href="${pageContext.request.contextPath}/admin/deptManage.jsp";
                    }
                }
            });
        });
        //对修改后的部门名称进行验证是否重复
        $("#depName2").blur(function(){
            if($("#depName2").val()==""){
                 $("#msg2").html("<font color='red'>部门名称不能为空!</font>");
                    $("#change").attr("disabled",true);
                    return false;
            }
            /* alert(depName.val()) */
            $.ajax({
                url : "${pageContext.request.contextPath}/DeptController?flag=checkDeptName&depName="+$("#depName2").val(),
                success:function(data){
                    if(data=="ok"){
                        $("#msg2").html("<font color='red'>该部门已存在!</font>");
                        $("#change").attr("disabled",true);
                    }else{
                        $("#msg2").html("<font color='green'>该部门可用</font>");
                        $("#change").attr("disabled",false);
                    }
                }
            });
        });
        //部门名称非空判断
        $("#change").click(function(){
            if($("#depName2").val()==""){
                 $("#msg2").html("<font color='red'>部门名称不能为空!</font>");
                    $("#change").attr("disabled",true);
                    return false;
            }
        });
        //排序非空判断
        $("#sort2").blur(function(){
            if($("#sort2").val()==""){
                 $("#msg2").html("<font color='red'>请填入优先级!</font>");
                    $("#change").attr("disabled",true);
                    return false;
            }
        });
    });
    

    相关文章

      网友评论

          本文标题:2018-10-30jquery实际应用

          本文链接:https://www.haomeiwen.com/subject/almgtqtx.html