0

我为重复表创建了一个 HMTL 和 Javascript。现在我想更改另一个与“重复表”具有相同类名的普通表。我怎样才能做到这一点?

我为重复表功能编写了完整的 Javascript。

    i = 1;

    var nAgt = navigator.userAgent;
    var browserName = navigator.appName;
    var nameOffset, verOffset, ix;

    // In MSIE, the true version is after "MSIE" in userAgent
    if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
        browserName = "Microsoft Internet Explorer";
    }
    // In Chrome, the true version is after "Chrome" 
    else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
        browserName = "Chrome";
    }

    // In Firefox, the true version is after "Firefox" 
    else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
        browserName = "Firefox";
    }


    if (browserName != "Firefox") {
        alert("Try using Firefox for better use");
    }

    function addbelow(x) {
        var index = x.rowIndex + 1;

        addrow(x, index);

        var table = document.getElementsByTagName('table')[0];

        var para = table.getElementsByTagName('p');
        for (count = 0; count < i; count++) {
            para[count].innerHTML = count + 1;
        }
    }
    function add(x) {

        var newindex = -1;
        addrow(x, newindex);
    }

    function addrow(x, index) {

        i = i + 1;

        //    var table = document.getElementsByTagName('table')[0];
        var table = document.getElementsByClassName('robert')[0];

        var row = table.insertRow(index);
        row.ondblclick = function () { addbelow(this) };

        var cell1 = row.insertCell(0);
        var image = document.createElement("IMG");
        image.src = "del.png";
        image.onclick = function () { remove(row) };
        cell1.appendChild(image);

        var cell2 = row.insertCell(1);
        var slno = document.createElement('p');
        slno.innerHTML = i;
        cell2.appendChild(slno);

        var cell3 = row.insertCell(2);
        var empcode = document.createElement('input');
        empcode.type = "text";
        empcode.onkeyup = function () { EnterOnlyNumbers(this) };
        cell3.appendChild(empcode);

        var cell4 = row.insertCell(3);
        var name = document.createElement('input');
        name.type = "text";
        cell4.appendChild(name);

        var cell5 = row.insertCell(4);
        var gender = document.createElement('Select');
        var option1 = document.createElement('option');
        var option2 = document.createElement('option');
        var option3 = document.createElement('option');

        option1.innerHTML = "Select";
        option2.innerHTML = "Male";
        option3.innerHTML = "Female";

        gender.appendChild(option1);
        gender.appendChild(option2);
        gender.appendChild(option3);

        cell5.appendChild(gender);

        var cell6 = row.insertCell(5);
        var Dept = document.createElement('select');
        Dept.name = "Dept";

        cell6.appendChild(Dept);

        load(row);

        var cell7 = row.insertCell(6);
        var prev = document.createElement('input');
        prev.type = "text";
        prev.name = "prev";
        prev.value = "0.00"
        prev.onkeyup = function () { addition(row), EnterOnlyNumbers(this) };

        cell7.appendChild(prev);

        var cell8 = row.insertCell(7);
        var current = document.createElement('input');
        current.type = "text";
        current.name = "current";
        current.value = "0.00";
        current.onkeyup = function () { addition(row), EnterOnlyNumbers(this) };

        cell8.appendChild(current);

        var cell9 = row.insertCell(8);
        var total = document.createElement('input');
        total.type = "text";
        total.name = "total";
        total.value = "0.00";
        total.readOnly = "readOnly";
        total.style.backgroundColor = "#EFEFEF";
        cell9.appendChild(total);


    }

    function remove(row) {

        row.parentNode.removeChild(row);

        count = i;
        i = 1;
        var table = document.getElementsByTagName('table')[0];
        var para = table.getElementsByTagName('p');
        for (i = 1; i < count; i++) {
            para[i].innerHTML = i + 1;
        }

    }

通过更改类名,我希望这些属性转到另一个表并使其成为重复表。

4

0 回答 0