-1

我正在向表格添加一行,并将一个ondblclick事件附加到单元格。该功能addrow运行良好,并且dblclick正在使用正确的参数将我带到seltogg。但是,var selbutton = document.getElementByIdinseltogg返回一个空值。当我在文档中的原始表格上调用seltogga时,它运行良好。dblclick所有参数“ selna”都有字母值,没有空格、特殊字符等。有人可以告诉我为什么 seltoggdocument.getElementById在我传递 id 时无法正确执行addrow;还有如何解决这个问题。

function addrow(jtop, sel4list, ron4list) {
    var tablex = document.getElementById('thetable');
    var initcount = document.getElementById('numrows').value;
    var sel4arr = sel4list.split(",");
    var idcount = parseInt(initcount) + 1;
    var rowx = tablex.insertRow(1);
    var jtop1 = jtop - 1;

    for (j = 0; j <= jtop1; j++) {
        var cellx = rowx.insertCell(j);
        cellx.style.border = "1px solid blue";

        var inputx = document.createElement("input");

        inputx.type = "text";
        inputx.ondblclick = (function() {
            var curj = j;
            var selna = sel4arr[curj + 2];
            var cellj = parseInt(curj) + 3;
            inputx.id = "cell_" + idcount + "_" + cellj;
            var b = "cell_" + idcount + "_" + cellj;
            return function() {
                seltogg(selna, b);
            }
        })();

        cellx.appendChild(inputx);
    } //end j loop
    var rowCount = tablex.rows.length;
    document.getElementById('numrows').value = rowCount - 1; //dont count header
} //end function addrow

function seltogg(selna, cellid) {
    if (selna == "none") {
        return;
    }
    document.getElementById('x').value = cellid; //setting up for the next function
    var selbutton = document.getElementById(selna); //*****this is returning null
    if (selbutton.style.display != 'none') { //if it's on
        selbutton.style.display = 'none';
    } //turn it off               
    else { //if it's off
        selbutton.style.display = '';
    } //turn it on  
} //end of function seltogg
4

1 回答 1

1

你试试,写下这句话: document.getElementById("numrows").value ondocument.getElementById('numrows').value

这是我的部分代码:

contapara=(parseInt(contapara)+1);

                document.getElementById("sorpara").innerHTML+="<li id=\"inputp"+contapara+"_id\" class=\"ui-state-default\"><span class=\"ui-icon ui-icon-arrowthick-2-n-s\"></span>"+$('#inputp'+contapara+'_id').val()+"</li>";   

看你必须使用这个“y not”。试试!!!!

于 2012-11-29T19:19:10.253 回答