我在页面创建了元素标签,也设了id 按理来说应该直接能找到,可试了好几次都是返回Null  怎么回事?

解决方案 »

  1.   

    是不是前面没写form的名字啊,把代码帖出来啊
      

  2.   

    document.getElementById("formname:id");
    一般这样就对了
      

  3.   


    <SCRIPT LANGUAGE="JavaScript">
    function makepopup(url,width,height,overflow)
    {
    if(width>640){width=640};
    if(height>480){height=480};
    if(overflow=""||!/^scroll|resize|both$/.test(overflow))
    {
    overflow="both";
    }
    var win=window.open(url,'','width='+width+',height='+height+',scrollbars='+(/^scroll|resize|both$/.test(overflow)?'yes':'no')+',status=yes,toolbar=no,menubar=no,location=no');
    return win;
    }
    document.getElementById("survey").onclick=function()//就是这行
    {
    var survey=makepopup(this.href,640,480,"scroll");
    return survey.closed
    }
    </SCRIPT>
    <BODY>
    <a href="http://www.baidu.com" id="survey">www.baidu.com</a>//我设这个id</BODY>
      

  4.   

    document.getElementById("survey").onclick=function()//就是这行
    {
    var survey=makepopup(this.href,640,480,"scroll");
    return survey.closed
    }=>window.onload = function(){
    document.getElementById("survey").onclick=function()//就是这行
    {
    var survey=makepopup(this.href,640,480,"scroll");
    return survey.closed
    }};
      

  5.   

    <a href="http://www.baidu.com" id="survey">www.baidu.com</a>放到 你的javascript前面也可以
      

  6.   

    document.getElementById("survey").onclick=function()//就是这行
    折行先于
    <a href="http://www.baidu.com" id="survey">www.baidu.com</a>//我设这个id
    执行,肯定是找不到dom元素了,最简单的方法是把js放到这行之后,或者用其他机制,确保dom载入了再执行上面的js代码
      

  7.   

    Dom没有加载完 你就去getElementById肯定是null了  
    cj205的可以 你也可以将那个function写在body标签的onload事件中