IE 10中的JS / JSp问题用于滚动条和排序

时间:2013-12-24 09:44:33

标签: javascript jsp

我正在使用滚动条和排序的表中遇到问题。

在兼容模式下,排序选项即将进入非兼容模式

请建议更改js或jsp

function makeScrollableTable(tbl, scrollFooter, height, hasSelectAllButton, hasAddButton, columnNo) {
    var c, pNode, hdr, ftr, wrapper, rect;
    //alert("Shree");
    if (typeof tbl == 'string') tbl = document.getElementById(tbl);
    pNode = tbl.parentNode;
    fixTableWidth(tbl);
    c = container.length;
    container[c] = document.createElement('<SPAN style="height: 100; overflow: auto;">');
    container[c].id = tbl.id + "Container";
    pNode.insertBefore(container[c], tbl);
    container[c].appendChild(tbl);
    container[c].style.width = tbl.clientWidth + 2 * tbl.clientLeft + scrollbarWidth();
    hdr = tbl.cloneNode(false);
    hdr.id += 'Header';
    hdr.appendChild(tbl.tHead.cloneNode(true));
    tbl.tHead.style.display = 'none';
    if (!scrollFooter || !tbl.tFoot) {
        ftr = document.createElement('<SPAN style="width:1;height:1;clip: rect(0 1 1 0);background-color:transparent;">');
        ftr.id = tbl.id + 'Footer';
        ftr.style.border = tbl.style.border;
        ftr.style.width = getActualWidth(tbl) + 2 * tbl.clientLeft;
        ftr.style.borderBottom = ftr.style.borderLeft = ftr.style.borderRight = 'none';
    } else {
        ftr = tbl.cloneNode(false);
        ftr.id += 'Footer';
        ftr.appendChild(tbl.tFoot.cloneNode(true));
        ftr.style.borderTop = 'none';
        tbl.tFoot.style.display = 'none';
    }
    wrapper = document.createElement('<table border=0 cellspacing=0 cellpadding=0>');
    wrapper.id = tbl.id + 'Wrapper';
    pNode.insertBefore(wrapper, container[c]);
    wrapper.insertRow(0).insertCell(0).appendChild(hdr);
    wrapper.insertRow(1).insertCell(0).appendChild(container[c]);
    wrapper.insertRow(2).insertCell(0).appendChild(ftr);
    wrapper.align = tbl.align;
    tbl.align = hdr.align = ftr.align = 'left';
    hdr.style.borderBottom = 'none';
    tbl.style.borderTop = tbl.style.borderBottom = 'none';
    // adjust page size
    if (c == 0 && height == 'auto') {
        onResizeAdjustTable();
        onResizeHandler = window.onresize;
        window.onresize = onResizeAdjustTable;
    } else {
        container[c].style.height = height;
    }
    //added by Venkatesh Bhat e-mail:vb106@dcx
    //alert("");
    if (hasSelectAllButton) {
        //include select all button
        var selButton = document.createElement('<input id="_myButton11" type="button" value="Select All" onClick="selectAll();">');
        insertNode(selButton);
    }
    if (hasAddButton) {
        var btext = '<input id="_myButton12" type="button" value="Add" onClick="posCursor(\'' + tbl.id + '\',\'' + columnNo + '\');">';
        var addButton = document.createElement(btext);
        insertNode(addButton);
    }
}
//added by Venkatesh Bhat e-mail:vb106@dcx
function insertNode(toInsert) {
    var tbs = document.getElementsByTagName('input');
    for (var i = 0; i < tbs.length; i++) {
        if (tbs[i].type == "button") {
            var backButton = tbs[i];
            var text = backButton.value.toUpperCase();
            if (text == "BACK") {
                var pNode = backButton.parentNode;
                pNode.insertBefore(toInsert, backButton);
                var textNode = document.createTextNode("  ");
                pNode.insertBefore(textNode, backButton);
                return;
            }
        }
    }
}
//added by Venkatesh Bhat e-mail:vb106@dcx
function posCursor(tbl, columnNo) {
    var table = document.getElementById(tbl);
    var rows = table.rows;
    for (var i = 0; i < rows.length; i++) {
        //cells = rows[i].cells;
        //if(columnNo > cells.length) continue;
        var cell = rows[i].cells[columnNo];
        if (getFocus(cell) == true) {
            selectCheckBox(rows[i].cells[0]);
            return;
        }
    }
}
//added by Venkatesh Bhat e-mail:vb106@dcx
function selectCheckBox(node) {
    var children = node.children;
    //check if this is a leaf node
    if (children.length == 0) {
        //if so then see if this is a checkbox input node
        if (node.tagName == "INPUT" && node.type == "checkbox") {
            node.checked = true;
            return true;
        } else {
            return false;
        }
    } else {
        //this is a parent node
        for (var i = 0; i < children.length; i++) {
            if (selectCheckBox(children[i]) == true) return true;
        }
    }
    return false;
}
//added by Venkatesh Bhat e-mail:vb106@dcx
function getFocus(node) {
    var children = node.children;
    //check if this is a leaf node
    if (children.length == 0) {
        //if so then see if this is a text input node
        if (node.tagName == "INPUT" && node.type == "text" && node.value == "") {
            node.focus();
            return true;
        } else {
            return false;
        }
    } else {
        //this is a parent node
        for (var i = 0; i < children.length; i++) {
            if (getFocus(children[i]) == true) return true;
        }
    }
    return false;
}
//added by Venkatesh Bhat e-mail:vb106@dcx
function selectAll() {
    //added by Venkatesh Bhat e-mail:vb106@dcx
    var button = document.getElementById('_myButton11');
    var butText = button.value;
    var tbs = document.getElementsByTagName('input');
    if (butText == 'Deselect All') {
        button.value = "Select All";
        for (var i = 0; i < tbs.length; i++) {
            if (tbs[i].type == "checkbox") {
                tbs[i].checked = false;
            }
        }
    } else {
        button.value = "Deselect All";
        for (var i = 0; i < tbs.length; i++) {
            if (tbs[i].type == "checkbox") {
                tbs[i].checked = true;
            }
        }
    }
}

function onResizeAdjustTable() {
    if (onResizeHandler) onResizeHandler();
    var rect = container[0].getClientRects()(0);
    var h = document.body.clientHeight - (rect.top + (document.body.scrollHeight - rect.bottom));
    container[0].style.height = (h > 0) ? h : 1;
}

function printPage() {
    var tbs = document.getElementsByTagName('TABLE');
    var e;
    for (var i = 0; i < container.length; i++) container[i].style.overflow = '';
    window.print();
    for (var i = 0; i < container.length; i++) container[i].style.overflow = 'auto';
}

0 个答案:

没有答案