JavaScript 错误 : NS_ERROR_XPC_BAD_CONVERT_JS

标签 javascript dom

我收到此 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>

还有...

<div id="IP_row_modify">
            <!-- dynamically adds new rows -->
</div>

这是用户将选择的 HTML 中的 select 语句...

<select id="requesttype" name="requestType"  onChange="checkF5Request(this.value);" tabindex="2">
                    <option value="...">...</option>
                    <option value="new">New Request</option>
                    <option value="modify">Modify Request</option>
                    <option value="delete">Removal Request</option>
                    <option value="iRule_redirect">iRule Redirect</option>

                    </select>

这是错误:

Error: uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]"  nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"  location: "JS frame :: https://request.psp :: generateRow :: line 358"  data: no]

最佳答案

所以你的new_IP_Octet2_Element是一个函数:

new_IP_Octet2_Element = function () { resolveMe(this.id); };

..无法传递给 appendChild() ,这需要一个 DOM 节点。

我不确定这个函数有什么意义,但是如果你删除它, objNEWVIP.appendChild(new_IP_Octet2_Element); 上的错误应该消失。

关于JavaScript 错误 : NS_ERROR_XPC_BAD_CONVERT_JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8330753/

相关文章:

javascript - 在 Javascript 中查找模式

javascript - c.replace 不是一个函数

PHP DOM XML 不在标记后打印出换行符

javascript - 如何在 JavaScript 中添加新元素?

javascript - 如何显示 DOM 元素

javascript - Axios:对多个 axios 实例使用相同的拦截器

javascript - 从上传的 CSV 文件创建数据表

javascript - 有没有办法让我把它变成一个函数或任何更有效的东西

javascript - CKEditor 4 基于工具栏配置的自定义构建

java - 如何使用 xml 文件中的数据创建 GUI?