日期:2014-05-16  浏览次数:20419 次

document.getElementById为空或不是对象
function   t_action(){
            if(http_request.readyState   ==   4){
            if(http_request.status   ==   200){
      //alert(http_request.responseText)
    var   string   =     http_request.responseText;     //ajax返回字符串
    var   array   =   string.split( "| ")   ;
    var   tid   =   array[0]       //有值
    var   text   =   array[1]       //有值
    alert(tid)         //tid   =   601
    //var   id   =   601
    document.getElementById(id).innerHTML   =   text;

//当用document.getElementById(id),document.getElementById(601)都能出来效果,
当用document.getElementById(tid)时就出现document.getElementById为空或不是对象的错误.


}   else   {
          alert( "页面有异常 "+http_request.status)
    }
      }
}

问题描述:在第一次运行的时候还没有碰到这个问题,后来不知道怎么的就出现了document.getElementById为空或不是对象.ajax返回的id就是不能用.直接赋值就能用.大家帮帮忙~~~先谢谢了!

------解决方案--------------------
document.getElementById(id).innerHTML = text;
改成
document.getElementById(uid).innerHTML = text;
------解决方案--------------------
可能tid字符串有空格,或回车什么的,处理一下看看
tid = tid.replace(/(^[\s]*)|([\s]*$)/g, " ");