Javascript通过javascript对象类将页面元素分配给变量

时间:2014-05-06 06:50:23

标签: javascript class object dom

我正在尝试将#Canvas css ID分配给我的类函数中的javascript变量。基本上我是为了这样做而不是去document.getElementByID("someID").appendChild(anotherElement)我可以去page.Add(javascript_object)当我执行下面的页面时,我收到以下错误:" Failed to execute 'appendChild' on 'Node': The new child element is null"。我究竟做错了什么?任何帮助,将不胜感激。感谢。

System.Web = {};
System.Web.UI={};
System.Web.UI.WebControls = {
Page: function (arg) {
    this.Node;
    this.Add = function (obj) {
        this.Node.appendChild(obj);
    }
    this.NodeCreate = function (args) {
        this.Node = document.getElementById(args);
    }
    this.NodeCreate(arg);
},
TextBoxMode:function(){
    this._MultiLine="";
    this.Password="password";
    this.SingleLine = "";
}
}

然后我这样称呼对象:

var x=document.createElement("div");
var page = new System.Web.UI.WebControls.Page("canvas");//Note: canvas is my css ID
page.Add(x);

0 个答案:

没有答案