<html>
<head>
    <title>test</title>
</head>
<body>
<div id="demo"></div>
<script>
function createobj(objid){
    this.getobj =  function(objid){
        return document.getElementById(objid);        
    }
    
    this.obj = this.getobj(objid);//这里,objid你写错了
    
    this.insert = function (content) {
        this.obj.innerHTML += content; //用this.obj
    }    
    //这里,多了个}
    this.alert1 = function (){
        alert("123")
    }
}
var o = new createobj("demo");
o.alert1();
o.insert("456");</script></body>
</html>

解决方案 »

  1.   

    <span id="mytest"></span>
    <br><script type="text/javascript" language="javascript">
    <!--
    function createObject(objId){ //取得自身的对象
    this.getObject=function(){
    return document.getElementById(objId);
    } //写入相关的内容
    this.insert=function(content){
      this.getObject().innerHTML=content;
    } //打印相关的消息 
    this.alertMsg=function(msg){
    alert(msg);
    }
    }var o = new createObject("mytest");
    o.alertMsg("hi,everyone");
    o.insert("add test");
    //-->
    </script>测试通过,直接运行,给我加分啊。。