Complex, and read to understand to hell

2010-10-21  来源:本站原创  分类:Web  人气:183 

/*
 *   Paging function
 * page   Requested page
 * rows   The number of records per page
 * queryStr   Is the search string
 * colStr   Was to find a field is empty all the fields to find
 * who   Page object, that is,  struts-config.xml   Configuration  path(  No '/')
 * return tbody  In the data, and data manipulation features of these  ,  Finally, we must add  (return;),  Otherwise, the call will be repeated  getDate()  Methods
 */

function getDate(page,rows,queryStr,colStr,who,w,h){
        if(who=="" || who=="undefined"){
                alert("  Please add the parameter to find the object name  ");
                return ;
        }
        //  The address of request data
        var url="../"+who+".do?page="+page+"&rows="+rows;
        if(queryStr!="" || queryStr!="undefined")
                url=url+"&queryStr="+queryStr;
        if(colStr!="" || colStr!="undefined")
                url=url+"&colStr="+colStr;
        //  Addresses turn into a unified ISO, back in the service side in a unified  UTF-8(  Chinese characters are encoded in a different browser, different, if not unified coding address  ,  In the server can not resolve the case of coexistence of multiple codes  )
        url=encodeURI(url);
        //ajax  Before waiting for the background gray  ,  Further action to prevent the user
        $(".mask").css("display","block").css("width","102%").css("height","100%");
        $(".mask-msg").css("display","block").css("top","49%").css("left","44%");

$.ajax({
    url: url,
    type: 'POST',
    data: null,
        timeout: 10000,
    error: function(){
        alert('  Error loading data  ~');
        $("#pageNum").val(0);
        $("#fromNum").html(0);
                $("#toNum").html(0);
        $("#totalNum").html(0);
                $("#totalPage").html(0);
                $(".mask").css("display","none");
                $(".mask-msg").css("display","none");
    },
    success: function(date){
                var objs=eval(date);
                total=objs.total;
                if(objs.total==0) {
                        $("#tDate tr").remove();
                        $("#tDate").append("<tr><td colspan=7>  No record  ~</td></tr>");
                        $("#pageNum").val(0);
                $("#fromNum").html(0);
                        $("#toNum").html(0);
                $("#totalNum").html(0);
                        $("#totalPage").html(0);
                        $(".mask").css("display","none");
                        $(".mask-msg").css("display","none");
                        return ;
                }
        $("#tDate tr").remove();
        //  The first column of the table shows the line number
        var lineNum=1;
        //  The first column shows the table background color for the title bar color
        var lineCSS=0;

        //  Defined by all thead th  tName,  Users to access data in json  ,  Subscript for the object obj
        var tName=gettNames();
        for(var i in objs.rows){
                var obj=objs.rows[i];
                //  Each line of information storage
                var outPut="";
                //  Interlaced Color
                if(lineNum%2==0)
                        outPut+="<tr"+lineNum+"</td>"
                else
                        outPut+="<tr><td>"+lineNum+"</td>"
                //  As a subscript for the tName  obj  The json data to the data columns
                for(var t=0;t<tName.length;t=t+1){
                        outPut+="<td>"+obj[tName[t]]+"</td>";
                }
                //  Definition of operations, where the compatibility function may be destructive
                outPut+="<td><div align=center><a href=#'../"+who+".do?command=updateDetail&num="+obj[tName[0]]+"','updateReport',"+w+","+h+");>  View  </a>"
                                +"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href=#'../"+who+".do?command=updateInput&num="+obj[tName[0]]+"','update"+who+"',"+w+","+h+");>  Modify  </a>"
                                +"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href=#'../"+who+".do?command=del"+who+"&num="+obj[tName[0]]+"',"+page+");>  Delete  </a></div></td></tr>";

                $("#tDate").append(outPut);

                //  The first column header color
                $("tbody tr td:eq("+lineCSS+")").css("background","#E8ECE8").css("padding","0px").css("text-align","center");
                //  Since the number of rows have been
                lineNum=lineNum+1;
                //  The next line of the first column
                lineCSS=lineCSS+tName.length+2;
        }

        //  Added to fill the form
        var keepOn=lineNum;
        if(keepOn<=rows){
                for(var i=0;i<=rows-keepOn;i=i+1){
                        //  Each line of information storage
                        var outPut="";
                        //  Interlaced Color
                        if(lineNum%2==0)
                                outPut+="<tr"+lineNum+"</td>";
                        else
                                outPut+="<tr><td>"+lineNum+"</td>";
                        for(var t=0;t<tName.length+1;t=t+1)
                                outPut+="<td></td>";
                        outPut+="</tr>";
                        $("#tDate").append(outPut);
                        $("tbody tr td:eq("+lineCSS+")").css("background","#E8ECE8").css("padding","0px").css("text-align","center");
                        //  Since the number of rows have been
                        lineNum=lineNum+1;
                        //  The next line of the first column
                        lineCSS=lineCSS+tName.length+2;
                }
        }

        var preClickIndex=-1;
        $("#tDate tr:odd").mouseover(function(){
                        $(this).removeClass("alt");
                        if(!$(this).hasClass("beClick"))
                                $(this).addClass("over");
                }).mouseout(function(){
                        $(this).removeClass("over");
                        if(!$(this).hasClass("beClick"))
                                $(this).addClass("alt");
                });

                $("#tDate tr:even").mouseover(function(){
                        if(!$(this).hasClass("beClick"))
                                $(this).addClass("over");
                }).mouseout(function(){
                        $(this).removeClass("over");
                });

                $("#tDate > tr").click(function(){
                        if(preClickIndex!=-1){
                                $("#tDate > tr:eq("+preClickIndex+")").removeClass("beClick");
                                if(preClickIndex%2==1)
                                        $("#tDate > tr:eq("+preClickIndex+")").addClass("alt");
                        }
                        $(this).addClass("beClick");
                        //index()  Method returns the current location of child elements
                        preClickIndex=$( "#tDate tr" ).index($(this)[0]);
                });

                //  Total Pages
                if(total%rows==0)
                        totalPage=parseInt(total/rows);
                else
                        totalPage=parseInt(total/rows)+1;

                //  The appropriate place to set the value of index.jsp page
                $("#pageNum").val(page);
        $("#fromNum").html((page-1)*rows);
                $("#toNum").html(page*rows);
        $("#totalNum").html(total);
                $("#totalPage").html(totalPage);
                $(".mask").css("display","none");
                $(".mask-msg").css("display","none");
        }
        });
        //(  Important  !)  Otherwise, when you click Next or Previous button, the page will perform series  ,  By the  1-2-4-8
        return ;
}

//  Function in response to user requests, do not put  getDate()  Mainly because the place is in error, the specific causes and manifestations  ,  Forgot
function opt(page,rows,queryStr,colStr,who,w,h){
        //  Jump to the destination page set
        $("#pageNum").keyup(function(event){
                var keycode=event.which;
                if(keycode==13){
                        setPage=parseInt($(this).val());
                        if(setPage==page)
                                return ;
                        if(setPage>totalPage)
                                page=totalPage;
                        else
                                page=setPage;
                        getDate(page,rows,queryStr,colStr,who,w,h);
                }
        });

        $("#reloadPage").click(function(){
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        $("#nextPage").click(function(){
                if(page==totalPage)
                        return ;
                page=page+1;
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        $("#prevPage").click(function(){
                if(page==1)
                        return ;
                page=page-1;
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        $("#lastPage").click(function(){
                if(total%rows==0)
                        totalPage=parseInt(total/rows);
                else
                        totalPage=parseInt(total/rows)+1;
                if(page==totalPage)
                        return ;
                page=totalPage;
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        //  After adding elements, jump to last page  ,  And  $("#lastPage").click()  Difference is added when the record on the last page will still refresh the page
        $("#lastPage").dblclick(function(){
                if(total%rows==0)
                        totalPage=parseInt(total/rows);
                else
                        totalPage=parseInt(total/rows)+1;
                page=totalPage;
                queryStr="";
                colStr="";
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        $("#firstPage").click(function(){
                if(page==1)
                        return ;
                page=1;
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        $("#setRows").change(function(){
                rows=parseInt($(this).val());
                page=1;
                $.cookie('pageSize',null,{ path: '/' });
                var date = new Date();
        date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
                $.cookie('pageSize',rows,{ path: '/', expires: date });
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        $("#SIMsearch").click(function(){
                var QueryStr=$("#SearchStr").val();
                queryStr=$.trim(QueryStr);
                colStr=$("#listColumn").val();
                page=1;
                getDate(page,rows,queryStr,colStr,who,w,h);
        });

        $("#SearchStr").keyup(function(event){
                var keycode=event.which;
                if(keycode==13){
                        $("#SIMsearch").click();
                }
        });

        $("#addBut").click(function(){
                openWin("/test2/"+who+"/add.jsp","add"+who,w,h);
        });

        getDate(page,rows,queryStr,colStr,who,w,h);
}

//  Date of validation
function validateCNDate( strValue ) {
        var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
        if(!objRegExp.test(strValue))
                return false;
        else{
                var arrayDate = strValue.split(RegExp.$1);
                var intDay = parseInt(arrayDate[2],10);
                var intYear = parseInt(arrayDate[0],10);
                var intMonth = parseInt(arrayDate[1],10); 

                if(intMonth > 12 || intMonth < 1) {
                        return false;
                }
                var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
                                '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31} 

                if(arrayLookup[parseInt(arrayDate[1])] != null) {
                if(intDay <= arrayLookup[parseInt(arrayDate[1])] && intDay != 0)
                        return true;
                } 

                if (intMonth-2 ==0) {
                        var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
                        if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
                                return true;
                        }
                }
        return false;
}

function checkDouble(obj){
        var v=obj.val();
    var value=$.trim(v);
        if(v=="" || v==null || isNaN(v)){
                obj.val("");
                obj.get(0).select();
                alert("  Please enter the number  ");
                return false;
        }
}

 function openWin(url,name,w,h,s){
        sb ="1";
        l = (screen.width - w)/2;
        t = (screen.height - h)/2;
        sFeatures = "left="+ l +",top="+ t +",height="+ h +",width="
                        +w+ ",center=1,scrollbars=" + sb + ",status=0,directories=0,channelmode=0";
        //  The address is converted to IOS code  , Anyway, with Chinese characters when passing parameters, different browsers use different coding passes  ,  Lead to server error
        var url=encodeURI(url);
        openwin = window.open(url , name , sFeatures );
        if (!openwin.opener)
                openwin.opener = self;
        openwin.focus();
        return openwin;
}

function del(url,page){
        var c = "  Are you sure you want to delete records  ?";
        if(confirm(c)){
                var url=encodeURI(url);
                $.post(url,null,function(data){
                        total=total-1;
                        //  Total Pages
                        if(total%rows==0)
                                totalPage=parseInt(total/rows);
                        else
                                totalPage=parseInt(total/rows)+1;
                        if(page>totalPage)
                                $("#lastPage").click();
                        else
                                $("#reloadPage").click();
                });
        }
}

function gettNames(){
        var size=$("#tt thead th").size();
        var tNames=new Array;
        for(var i=1;i<size-1;i=i+1)
                tNames[i-1]=$("#tt thead th:eq("+i+")").attr("tName")
        return tNames;
}

function sort(index,who,w,h){
        //  Total number of column line
        var tdNums=$("#tDate tr:first").children().size();
        //  Total number of lines, including blank lines
        var rows=$("#tDate").children().size();
        //  The actual data stored in each row  (  Beheaded to the end  )

        //  Save traverse each row of data values
        var allDate=new Array();
        //  Non-empty rows
        var realLength=0;
        //  All data have been obtained in the form of an array of saved allDate  ,  Ajax data obtained with the above content transmitted over the same
        for(var i=0;i<rows;i=i+1){
                var trDate=new Array(tdNums-2);
                for(var j=1;j<tdNums-1;j=j+1){
                        //  Remove the first  :  Serial number and the last line  :  Operation  .
                        trDate[j-1]=$("#tDate tr:eq("+i+") td:eq("+j+")").html();
                }
                //  Not add an empty line to determine the standard  ,  The first line, that is,  num  Field is empty, because  num  Primary key, can not be empty  ,  So after the application is to determine the primary key column is empty
                if($("#tDate tr:eq("+i+") td:eq(1)").html()!=null && $("#tDate tr:eq("+i+") td:eq(1)").html()!=""){
                        //  Replace Click to sort out with the first column of data
                        swap(trDate,0,index);
                        //  After replacing the data stored
                        allDate[i]=trDate;
                        realLength=realLength+1;
                }
        }

        //  Sort
        allDate.sort();

        var FinalDate=new Array(realLength);
        //  The sorted array of data in each row has data on the exchange in return  .
        for(var i=0;i<realLength;i=i+1){
                var getTrDate=allDate[i];
                swap(getTrDate,index,0);
                FinalDate[i]=getTrDate;
        }
        //  Del function as the parameter to be passed  ,  After the jump back to the original page to remove
        var page=$("#pageNum").val();
        $("#tDate tr").remove();
        //  The first column of the table shows the line number
    var lineNum=1;
    //  The first column shows the table background color for the title bar color
    var lineCSS=0;

    for(var i in FinalDate){
        var obj=FinalDate[i];
        //  Each line of information storage
        var outPut="";
        //  Interlaced Color
        if(lineNum%2==0)
                outPut+="<tr"+lineNum+"</td>"
        else
                outPut+="<tr><td>"+lineNum+"</td>"
        //  As a subscript for the tName  obj  The json data to the data columns
        for(var t=0;t<tdNums-2;t=t+1){
                outPut+="<td>"+obj[t]+"</td>";
        }
        //  Definition of operations, where the compatibility function may be destructive
        outPut+="<td><div align=center><a href=#'../"+who+".do?command=updateDetail&num="+obj[0]+"','updateReport',"+w+","+h+");>  View  </a>"
                +"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href=#'../"+who+".do?command=updateInput&num="+obj[0]+"','update"+who+"',"+w+","+h+");>  Modify  </a>"
                        +"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href=#'../"+who+".do?command=del"+who+"&num="+obj[0]+"',"+page+");>  Delete  </a></div></td></tr>";

        $("#tDate").append(outPut);

        //  The first column header color
        $("tbody tr td:eq("+lineCSS+")").css("background","#E8ECE8").css("padding","0px").css("text-align","center");
        //  Since the number of rows have been
        lineNum=lineNum+1;
        //  The next line of the first column
        lineCSS=lineCSS+tdNums;
     }

     var keepOn=realLength;
     if(keepOn<rows){
        for(var i=0;i<rows-keepOn;i=i+1){
                //  Each line of information storage
                var outPut="";
                //  Interlaced Color
                if(lineNum%2==0)
                        outPut+="<tr"+lineNum+"</td>";
                else
                        outPut+="<tr><td>"+lineNum+"</td>";
                for(var t=0;t<tdNums-1;t=t+1)
                        outPut+="<td></td>";
                outPut+="</tr>";
                $("#tDate").append(outPut);
                $("tbody tr td:eq("+lineCSS+")").css("background","#E8ECE8").css("padding","0px").css("text-align","center");
                //  Since the number of rows have been
                lineNum=lineNum+1;
                //  The next line of the first column
                lineCSS=lineCSS+tdNums;
        }
     }

     var preClickIndex=-1;
    $("#tDate tr:odd").mouseover(function(){
                $(this).removeClass("alt");
                if(!$(this).hasClass("beClick"))
                        $(this).addClass("over");
        }).mouseout(function(){
                $(this).removeClass("over");
                if(!$(this).hasClass("beClick"))
                        $(this).addClass("alt");
        });

        $("#tDate tr:even").mouseover(function(){
                if(!$(this).hasClass("beClick"))
                        $(this).addClass("over");
        }).mouseout(function(){
                $(this).removeClass("over");
        });

        $("#tDate > tr").click(function(){
                if(preClickIndex!=-1){
                        $("#tDate > tr:eq("+preClickIndex+")").removeClass("beClick");
                        if(preClickIndex%2==1)
                                $("#tDate > tr:eq("+preClickIndex+")").addClass("alt");
                }
                $(this).addClass("beClick");
                //index()  Method returns the current location of child elements
                preClickIndex=$( "#tDate tr" ).index($(this)[0]);
        });
        trDate=null;
        allDate=null;
        FinalDate=null;
        return ;
}

function swap(arr,i,j){
        var temp="";
        temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;
}
相关文章
  • Complex, and read to understand to hell 2010-10-21

    /* * Paging function * page Requested page * rows The number of records per page * queryStr Is the search string * colStr Was to find a field is empty all the fields to find * who Page object, that is, struts-config.xml Configuration path( No '/') *

  • Extreme Programming 2009-09-11

    Extreme Programming (eXtreme Programming, or XP) by Kent Beck in 1996. Kent Beck in the early nineties, when working with Ward Cunningham, has been to explore new software development method of software development can be more simple and effective. K

  • java there is procedure call 2010-03-29

    CallableStatement object for all of the DBMS provides a standard form called the stored procedure approach. Stored procedure has been stored in the database. That have been stored procedure call is contained in the contents of the CallableStatement o

  • jdk 1.6 New Features 2010-03-29

    By the end of 2006, Sun released Java Standard Edition 6 (Java SE 6) of the final official version, code-named Mustang (Mustang). The sixth version of the Java Platform, Standard Edition (Java SE), code-named Mustang, has released the second Beta ver

  • Fourteen common Java development tools, and its characteristics (transfer) 2010-03-29

    1, JDK (Java Development Kit) Java Development Kit From the novice point of view, using JDK develop Java programs can quickly understand the program, the relationship between the various parts of the code will help to understand Java object-oriented

  • javascript function method call () and apply () to switch 2010-03-17

    call () and apply () of the first parameter is the function to be called an object, in the function body of this parameter is the value of this keyword. call () the remaining parameters are passed to the value of the function to call. Is structured a

  • JAVA in a pointer, the reference and the object's clone (switched from IBM) 2010-03-18

    One advantage of Java language is the repeal of the concept of pointers, but also led to a number of programmers in the programming often overlook the distinction between objects and references, this paper will attempt to clarify the concept. And bec

  • JForum source code of (11) 2010-03-29

    First experience without signing in, click the "keynote": Jump to the login page, login is successful, jump to the "new topic." This is common in many Web applications, "permission to intercept." JForum is how to achieve it?

  • Software architecture design points 2010-03-26

    Today's software industry, software architecture decisions, and the software is good or bad. Other than people like skeleton, skeleton, etc. If people are not good, then people are very vulnerable. Software architecture in software engineering that w

  • vc access to the database 2010-04-02

    ODBC (Open Database Connectivity, Open Database Connectivity) is a database access Microsoft defined standard, it provides a standard database access methods to access different database provider database, is essentially a set of database access API.

  • OWB 11gR2 Repository Installation 2010-02-08

    Wanted to write about how to install the OWB repository of. But a search online found a OWB 11gR1 in: http://tech.ddvip.com/2009-05/1242296514119157.html OWB11gR2 repository with the 11gR1 installation process is similar to not write. Students intere

  • Strongly recommended <lying wireless communications> 2010-02-28

    For a long time, been looking for an easy to understand for non professional books about wireless communication, but simply turned over a lot, without exception, because it is too specialized, boring, difficult and frightening away. Day noon bookstor

  • C / C + + basics: typedef Usage Summary 2010-04-17

    Go http://www.kuqin.com/language/20090322/41866.html First, the four purposes Use a: Define a type alias, not just a simple macro substitution. Same statement can be used as a pointer type of multiple objects. For example: char * pa, pb; / / This is

  • [Change] Java learning topics for (12) 2010-04-21

    This should have been a few talk about ORM framework, but I have not completely summed up, so here's the first JVM into a learning experience. As a Java programmer, if the JVM do not understand the working principle, it is difficult to grasp from the

  • Analysis of SalesForce 2010-04-25

    Source: http://www.salesforce.com/cn/platform/what-is-it.jsp http://wiki.developerforce.com/index.php/Database_Services Running the application through the cloud "Cloud computing" is a new model, significantly changed the way people build and ru

  • The installation of Windows, opentaps 2010-04-26

    The installation of Windows, opentaps ------------------------------- Test install environmental systems: WindowsXp (64 Bit , 2G) Database: mysql5.5 Jdk: 1.6 opentaps version: 1.4.0 IDE: eclipse3.4 ------------------------------- I am finishing the d

  • Zen zen of python python 2010-05-28

    Some fans feel are talented python, had seen "python Eight Honors and Eight Shames", also "python rose Declaration", this time to see a "zen of python" (python of Zen). Prior to learning php When not seen such things. The Zen

  • JavaScript array of rapid cloning (slice () function) and the array of sorting. Out of order and search (sort () function) 2010-06-29

    JavaScript in the operation of the variables are passed by reference, rather on the same array. Two days ago you want to copy an array, has struggled to find ways (the method I iterate is absolutely not used) Accidentally picked up "JavaScript The De

  • Oracle 8i.9i.10g.11g between the various versions of the new features of relatively 2010-07-01

    Oracle 9i 8i more than what new features? In brief: 9i easier to manage. Detail: Concurrent cluster, 8i OPS upgraded to 9i RAC, 8i between nodes to exchange information with the hard drive, 9i node network cable between the high-speed cache fusion (C

  • typedef Usage Summary 2010-07-16

    This two-day look at procedures, found that many places use typedef, defined in the structure, there are an array of other places a lot of use. But in some places is not very clear, this afternoon, wanted to study how . Internet search, I have a lot