English 中文(简体)
j 内容 a Id 严重错误
原标题:javascript getElementById appendChild error

i am having a problem with javascript and i dont know how to solve it. i am having this code

function addtask(tab){
        var tasktag = document.createElement( tr );
        var task = document.getElementById(tab).getElementsByTagName( tr ).length+1;
        task = tab+ r +task;
        tasktag.setAttribute( id ,task);
        document.getElementById(tab).appendChild(tasktag);
        var tasktag2 = document.createElement( td );
        var task2 = document.getElementById(task).getElementsByTagName( td ).length+1;
        task2 = task+ c +task2;
                alert(task2);
        tasktag2.setAttribute( id ,task2);
        tasktag2.innerHTML =  +task2+    <br><input id= btn1  type= button  value= remove  onClick="removeElement(  +num+  , body )" /> ;
        document.getElementById(task).appendChild(task2);
}`

i get "Couldn t convert JavaScript argument arg 0 [nsIDOMHTMLTableRowElement.appendChild]"(from firebug). while this code works perfect

`var num;
function addlist(){
        var divTag = document.createElement( table );
        if(num==undefined){num = 1;}
        else{numi = num.split("t")
            num=parseInt(numi[1])+1;}
        num =  t +num;
        divTag.setAttribute( id ,num);
        divTag.setAttribute( align , left ); 
        divTag.setAttribute( style , margin:7px; ); 
        divTag.setAttribute( border ,1); 
        document.body.appendChild(divTag);
        var divTag2 = document.createElement( tr );
        var num2 = document.getElementById(num).getElementsByTagName( tr ).length+1;
        num2 = num+ r +num2;
        divTag2.setAttribute( id ,num2);
        document.getElementById(num).appendChild(divTag2);
        var divTag3 = document.createElement( td );
        var num3 = document.getElementById(num2).getElementsByTagName( td ).length+1;
        num3 = num2+ c +num3;
        divTag3.setAttribute( id ,num3);
        divTag3.innerHTML =  +num+    <br><input id= btn1  type= button  value= remove  onClick="removeElement(  +num+  , body )" /><br><input id= btn2  type= button  value= task  onClick="addtask(  +num+  )" /> ;
        document.getElementById(num2).appendChild(divTag3);
    }

为什么发生这种情况? 谢谢大家的时间

最佳回答

When working with tables, you have to use slightly different JavaScript functions:

var row = table.insertRow(table.rows.length);
row.id = ...;

Try re-working their Code to use insertRow und appendChild, as I am lazy.

问题回答

暂无回答




相关问题
Pass all arguments of a method into NSLog

I print out something to the console using NSLog(). Is there a way to pass all the current method s arguments to NSLog(), or any other function or method, without looking at each of them explicitly? ...

Redirecting Command-line Arguments for Bootstrapping

I am trying to rewrite the following program in C instead of C# (which is less portable). It is obvious that "int system ( const char * command )" will be necessary to complete the program. Starting ...

A question about JavaScript s slice and splice methods

I came across the following code: var f = function () { var args = Array.prototype.slice.call(arguments).splice(1); // some more code }; Basically, the result in args is an array that is a ...

To understand Python s optparse

Thank you for quack in pointing out the off-by-one! The following code is my first attempt in writing code with Optparse. How can you fix the following bug in getting the help by Optparse? #!/usr/...

Read from File, or STDIN

I ve written a command line utility that uses getopt for parsing arguments given on the command line. I would also like to have a filename be an optional argument, such as it is in other utilities ...

C++ Access to command line arguments outside main?

I have a couple command line apps that both end up calling into com objects. Rather than adding new interface to these com objects, can they access the parameters passed from the command line? Edit: ...

热门标签