首页 新闻 会员 周边

js问题,为什么获取不了id元素??求解

0
悬赏园豆:10 [已解决问题] 解决于 2012-07-22 22:13
function log(i){ return console.log(i); } 

    function $ (id)
    {
        if(typeof id === "string"){
            return document.getElementById(id);
        }else{
            return id;
        }
    }
    function PicList(){
        this.elem = $(arguments[0]);
        this.arr = [];
        var iTarget = [
            { left:0 },
            { left:50 },
            { left:100 },
            { left:150 },
            { left:200 }
        ];
        
        this.run();
    }
    PicList.prototype.run = function(){
        log(this.elem)  //null
    }
    Animate.prototype = new PicList("wrap");
    function Animate(){
        log(this.arr)
    }
    var obj = new Animate();
//HTML
<div id="wrap">    </div>

PicList.prototype.run = function(){ log(this.elem) //null } 这句获取了空值...哪里出错了?

深蓝色梦想的主页 深蓝色梦想 | 初学一级 | 园豆:6
提问于:2012-06-17 04:29
< >
分享
最佳答案
0

1、先确认run函数被正确的调用。(使用alert

2、确认$这个函数在调用的时候的结果是否正确

3、确认PicList构造函数的正确调用。

收获园豆:10
无之无 | 大侠五级 |园豆:5095 | 2012-06-17 06:09
其他回答(1)
0

很简单。

你的js执行在html加载之前。

.! | 园豆:402 (菜鸟二级) | 2012-07-12 17:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册