js 표 정렬 & 문자열 공백 제거

3176 단어 문자열
// a:   bool:  true false    Str: 



function newUnitSort(a, bool, str) {



                            var oTable = document.getElementById('ATEST');

                            var arr = [];

                            for (var i = 0; i < oTable.tBodies[0].rows.length; i++)

                            {

                                arr[i] = oTable.tBodies[0].rows[i];

                            }



                            if (bool) {

                                if (str === "name") {

                                    nameSortUp = false;

                                }

                                if (str === "type") {

                                    typeSortUp = false;

                                }

                                if (str === "ip") {

                                    ipSortUp = false;

                                }

                                arr.sort(function(tr1, tr2) {

                                    var str1 = tr1.cells[a].innerHTML;

                                    var str2 = tr2.cells[a].innerHTML;

                                    if (str1.localeCompare(str2) === -1) {

                                        return -1;

                                    } else if (str1.toLocaleString().localeCompare(str2) === 1) {

                                        return 1;

                                    } else {

                                        return 0;

                                    }

                                });

                            } else {

                                if (str === "name") {

                                    nameSortUp = true;

                                }

                                if (str === "type") {

                                    typeSortUp = true;

                                }

                                if (str === "ip") {

                                    ipSortUp = true;

                                }

                                arr.sort(function(tr1, tr2) {

                                    var str1 = tr1.cells[a].innerHTML;

                                    var str2 = tr2.cells[a].innerHTML;

                                    if (str1.localeCompare(str2) === -1) {

                                        return 1;

                                    } else if (str1.toLocaleString().localeCompare(str2) === 1) {

                                        return -1;

                                    } else {

                                        return 0;

                                    }

                                });

                            }

                            for (var i = 0; i < arr.length; i++)

                            {

                                oTable.tBodies[0].appendChild(arr[i]);

                            }

                            



                        }


  
문자열 공백 제거:
String.prototype.NoSpace = function() { return this.replace(/\s+/g, ""); };

좋은 웹페이지 즐겨찾기