JavaScript错误:NS\u错误\u XPC\u错误\u转换\u JS

JavaScript错误:NS\u错误\u XPC\u错误\u转换\u JS,javascript,dom,Javascript,Dom,我得到了这个JavaScript错误,做了一些研究,人们说了一些关于实例化对象的事情 function generateRow() { var i = pageCounter.getIP_count(); //common sense counting i++; var objNEWVIP = document.getElementById("IP_row_new"); var objMODIFYVIP = document.getElementB

我得到了这个JavaScript错误,做了一些研究,人们说了一些关于实例化对象的事情

function generateRow() {    
    var i = pageCounter.getIP_count();
    //common sense counting
    i++;
    var objNEWVIP = document.getElementById("IP_row_new");
    var objMODIFYVIP = document.getElementById("IP_row_modify");

    //common DOM elements
    var memberNum = document.createTextNode('Member IP'+ i + '\u00a0');
    var brNode = document.createElement('br');
    var nbspSpace = document.createTextNode('\u00a0');
    var resolvesTextNode = document.createTextNode('Resolves: \u00a0');

    //new_IP_Octet1_Element
    var new_IP_Octet1_Element = document.createElement('input');
    new_IP_Octet1_Element.setAttribute('type','text');
    new_IP_Octet1_Element.setAttribute('maxlength','3');
    new_IP_Octet1_Element.setAttribute('size','3');
    new_IP_Octet1_Element.setAttribute('name','IP'+i+'_octet1');
    new_IP_Octet1_Element.setAttribute('id','IP'+i+'_octet1');
    new_IP_Octet1_Element.setAttribute('value','167');
    new_IP_Octet1_Element.setAttribute('size','3');
    new_IP_Octet1_Element.setAttribute('hostname','IP'+i+'_hostname');
    new_IP_Octet1_Element.onchange =  function () { resolveMe(this.id); };
    //new_IP_Octet1_Element.setAttribute('onchange', 'resolveMe(this.id);');

    //new_IP_Octet2_Element
    var new_IP_Octet2_Element = document.createElement('input');
    new_IP_Octet2_Element.setAttribute('type','text');
    new_IP_Octet2_Element.setAttribute('maxlength','3');
    new_IP_Octet2_Element.setAttribute('size','3');
    new_IP_Octet2_Element.setAttribute('name','IP'+i+'_octet2');
    new_IP_Octet2_Element.setAttribute('id','IP'+i+'_octet2');
    new_IP_Octet2_Element.setAttribute('value','69');
    new_IP_Octet2_Element.setAttribute('size','3');
    new_IP_Octet2_Element = function () { resolveMe(this.id); };
    //new_IP_Octet2_Element.setAttribute('onchange', 'resolveMe(this.id);');

    //new_IP_Octet3_Element
    var new_IP_Octet3_Element = document.createElement('input');
    new_IP_Octet3_Element.setAttribute('type','text');
    new_IP_Octet3_Element.setAttribute('maxlength','3');
    new_IP_Octet3_Element.setAttribute('size','3');
    new_IP_Octet3_Element.setAttribute('name','IP'+i+'_octet3');
    new_IP_Octet3_Element.setAttribute('id','IP'+i+'_octet3');
    new_IP_Octet3_Element.setAttribute('value','0');
    new_IP_Octet3_Element.setAttribute('size','3');
    new_IP_Octet3_Element = function () { resolveMe(this.id); };
    //new_IP_Octet3_Element.setAttribute('onchange', 'resolveMe(this.id);');

    //new_IP_Octet4_Element
    var new_IP_Octet4_Element = document.createElement('input');
    new_IP_Octet4_Element.setAttribute('type','text');
    new_IP_Octet4_Element.setAttribute('maxlength','3');
    new_IP_Octet4_Element.setAttribute('size','3');
    new_IP_Octet4_Element.setAttribute('name','IP'+i+'_octet4');
    new_IP_Octet4_Element.setAttribute('id','IP'+i+'_octet4');
    new_IP_Octet4_Element.setAttribute('value','0');
    new_IP_Octet4_Element.setAttribute('size','3');
    new_IP_Octet4_Element = function () { resolveMe(this.id); };
    //new_IP_Octet4_Element.setAttribute('onchange', 'resolveMe(this.id);');

    //make SPAN for DNS reverse resolution
    var reverseDNS_Element = document.createElement('span');
    reverseDNS_Element.setAttribute('id','IP'+i+'_hostname');
    reverseDNS_Element.setAttribute('name','IP'+i+'_hostname');

    //output
    if (document.getElementById('requesttype').value == "new") {
        objNEWVIP.appendChild(memberNum);
        objNEWVIP.appendChild(new_IP_Octet1_Element);
        objNEWVIP.appendChild(nbspSpace);
        objNEWVIP.appendChild(new_IP_Octet2_Element);
        objNEWVIP.appendChild(nbspSpace);
        objNEWVIP.appendChild(new_IP_Octet3_Element);
        objNEWVIP.appendChild(nbspSpace);
        objNEWVIP.appendChild(new_IP_Octet4_Element);
        objNEWVIP.appendChild(nbspSpace);
        objNEWVIP.appendChild(resolvesTextNode);
        objNEWVIP.appendChild(reverseDNS_Element);
        objNEWVIP.appendChild(brNode);
    }
     if (document.getElementById('requesttype').value == "modify") {
        objMODIFYVIP.appendChild(memberNum);
        objMODIFYVIP.appendChild(new_IP_Octet1_Element);
        objMODIFYVIP.appendChild(nbspSpace);
        objMODIFYVIP.appendChild(new_IP_Octet2_Element);
        objMODIFYVIP.appendChild(nbspSpace);
        objMODIFYVIP.appendChild(new_IP_Octet3_Element);
        objMODIFYVIP.appendChild(nbspSpace);
        objMODIFYVIP.appendChild(new_IP_Octet4_Element);
        objMODIFYVIP.appendChild(nbspSpace);
        objMODIFYVIP.appendChild(resolvesTextNode);
        objMODIFYVIP.appendChild(reverseDNS_Element);
        objMODIFYVIP.appendChild(brNode);
    }
    pageCounter.addMethod("ip_count"); //increment after adding row
}
generateRow()函数在用户单击按钮时被调用

我正在实例化什么对象…我该如何做

我认为问题出在你身上

var objNEWVIP = document.getElementById("IP_row_new");
var objMODIFYVIP = document.getElementById("IP_row_modify");
但我不确定如何在这个位置创建新对象

这是计数器函数

function counterObj(){
    //object to keep track of all counts across all forms
    this.ipCountTotal = 0;
    this.dnsElementTotal = 0;
    this.approverTotal = 0;
    //input methods mapping
    this.clear = clearing;
    this.addMethod = add; 

    //retreval methods mapping
    this.getIP_count = function() { return(this.ipCountTotal);};
    this.getDNS_count = function() { return(this.dnsElementTotal);};
    this.getApprover_count = function() { return(this.approverTotal);};

    //addMethod
    function add(strType){
        switch(strType) {
            case "dns_count":
                this.dnsElementTotal++;
                break;
            case "ip_count":
                this.ipCountTotal++;
                break;
            case "approver_count":
                this.approverTotal++;
                break;
        } //end swtich strType

    }



    //clear all
    function clearing(){
        this.ipCountTotal = 0;
        this.dnsElementTotal = 0;
        this.approverTotal = 0;
    }

}
声明如下:

var pageCounter = new counterObj();
 pageCounter.clear()
下面是html div

<div id="ip_row_new" title="please provide the ip address of each endpoint member.">

</div>

因此,您的
新的\u IP\u Octet2\u元素是一个函数:

new_IP_Octet2_Element = function () { resolveMe(this.id); };
…无法传递给需要DOM节点的
appendChild()


我不确定这个函数的意义是什么,但是如果删除它,
objNEWVIP.appendChild(new_IP_Octet2_元素)上的错误应该走了。

谢谢你,尼克雷。你让我走对了路

问题在于这四条线的差异

new_IP_Octet1_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet2_Element =  function () { resolveMe(this.id); };
new_IP_Octet3_Element =  function () { resolveMe(this.id); };
new_IP_Octet4_Element =  function () { resolveMe(this.id); };
需要将.onchange属性添加到DOM对象

new_IP_Octet1_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet2_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet3_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet4_Element.onchange =  function () { resolveMe(this.id); };

它是在使用appendChild函数时出现的。运行调试器时,我在此行objNEWVIP.appendChild(new_IP_Octet2_元素)上得到错误;您必须显示HTML代码和
pageCounter
的定义。当前代码不包含任何明显的缺陷。
new_IP_Octet2_Element = function () { resolveMe(this.id); };
new_IP_Octet1_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet2_Element =  function () { resolveMe(this.id); };
new_IP_Octet3_Element =  function () { resolveMe(this.id); };
new_IP_Octet4_Element =  function () { resolveMe(this.id); };
new_IP_Octet1_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet2_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet3_Element.onchange =  function () { resolveMe(this.id); };
new_IP_Octet4_Element.onchange =  function () { resolveMe(this.id); };