你是IE里吗?只有IE才能这样写:document.all.xxx.innerHTML="sina.com"

解决方案 »

  1.   

    另外可能是:你把代码写到了<div id=xxx>之前了,对象还没有生成就去访问了
      

  2.   

    <html>
    <body>
    <div id=xxx>晕菜</div>
    <table id=yyy>
    <tr><td>晕菜</td></tr>
    </table><button onclick="document.all.xxx.innerHTML = 'sina.com'">set sina.com</button><br><br><button onclick="document.all.yyy.rows(0).cells(0).innerHTML = 'sohu.com'">set sohu.com</button>
    </body>
    </html>
      

  3.   

    <div id=xxx>csdn.net</div>
    <script>
    document.all.xxx.innerHTML="sina.com"
    </script>
    是正确的,而<script>
    document.all.xxx.innerHTML="sina.com"
    </script>
    <div id=xxx>csdn.net</div>
    应该是错误的,会提示没有对象的
      

  4.   

    net_lover(孟子E章) 分析得很有道理。我只补充一句,对表格不要用普通的方式用innerHTML,我提供两种方式:。<html>
    <body>
    <table id=yyy>
    <tr><td id=zzz>晕菜</td></tr>
    </table>
    <button onclick="document.all.yyy.rows(0).cells(0).innerHTML = 'sohu.com'">set td 1</button>
    <button onclick="document.all.item('zzz').innerHTML = 'lanbor.com'">set td 2</button>
    </body>
    </html>
      

  5.   

    net_lover(孟子E章) 分析得很有道理。我只补充一句,对表格不要用普通的方式用innerHTML,我提供两种方式:。<html>
    <body>
    <table id=yyy>
    <tr><td id=zzz>晕菜</td></tr>
    </table>
    <button onclick="document.all.yyy.rows(0).cells(0).innerHTML = 'sohu.com'">set td 1</button>
    <button onclick="document.all.item('zzz').innerHTML = 'lanbor.com'">set td 2</button>
    </body>
    </html>
      

  6.   

    其实,我本意是iframe的一个页面调用的,parent.document.all.xxx.innerHTML="sina.com";
    大家看看能不能搞定呢?
      

  7.   

    等给你写个例子...(顺便问一句,这个iframe和主页面是在同一服务器上吗?)
      

  8.   

    a.html
    ----------------------------------------------------------
    <html>
    <body>
    <div id=xxx></div>
    <iframe width=100 height=100 src="b.html"></iframe>
    </body>
    </html>b.html
    -----------------------------------------------------------
    <html>
    <body>
    <button onclick="parent.document.all.xxx.innerHTML='sohu.com'">set0</button><br>
    <button onclick="parent.document.all.xxx.innerHTML='sina.com'">set1</button>
    </body>
    </html>如果a,b不在一个服务器上就不行了,这叫跨域操作。
      

  9.   

    在同一个服务器,不过iframe里面的叶面是定时刷新的
      

  10.   

    没问题呀。??!!a.html
    --------------------------------------------------
    <html>
    <body>
    <div id=xxx></div>
    <iframe width=100 height=100 src="b.html"></iframe>
    </body>
    </html>b.html
    --------------------------------------------
    <html>
    <head>
    <script>
    var i=0;
    function setParent()
    {
      parent.document.all.xxx.innerHTML = ++i;
    }
    setInterval("setParent()",1000);
    </script>
    </head>
    </html>
      

  11.   

    我的两文件
    --------------------index.htm------------------------
    <HTML><HEAD>
    <TITLE>在线名单</TITLE>
    <META content="text/html; charset=gb2312" http-equiv=Content-Type>
    <link rel=stylesheet type="text/css" href="../../css/ecall.css">
    <style>
      #item {position:absolute; visibility:visible; left:0px}
    </style>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- 
    //setTimeout("location.reload()",10000);
    function opensend(htm)
    {
       window.open(htm,'发信息','Status=no,scrollbars=no,resizable=no,width=395,height=162');
    }var isNS=(document.layers);
    var _all=(isNS)? '' : 'all.' ;
    var _style=(isNS)? '' : '.style' ;
    var _visible=(isNS)? 'show' : 'visible';
    var w_x, w_y, item, okscroll=false, godown;function init(){
    item=eval('document.'+_all+'item'+_style);
    getwindowsize();
    item.visibility=_visible;
    scrollpage();
    }function getwindowsize() {
    w_x=(isNS)? window.innerWidth-5 : document.body.clientWidth;
    w_y=(isNS)? window.innerHeight : document.body.clientHeight;
    (isNS)? item.clip.width=42: item.width=42;
    (isNS)? item.clip.height=20 : item.height=20;
    moveitem();
    }function resizeNS() {
    setTimeout('document.location.reload()',400);
    }function moveitem() {
    if (isNS) {
    item.moveTo((pageXOffset+w_x-70),(w_y+pageYOffset-50))
    }else{
    item.pixelLeft=document.body.scrollLeft+w_x-25;
    item.pixelTop=w_y+document.body.scrollTop-230;
    }
    }window.onload=init;
    (isNS) ? window.onresize=resizeNS : window.onresize=getwindowsize ;function scrollpage() {
    status = '';
    if (okscroll) {
    if (godown) {
    (isNS)? window.scrollBy(0,8) : window.scrollBy(0,8) ;
    } else {
    (isNS)? window.scrollBy(0,-8) : window.scrollBy(0,-8) ;
    }
    }
    moveitem();
    setTimeout('scrollpage()', 40);
    }
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }function MM_findObj(n, d) { //v4.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && document.getElementById) x=document.getElementById(n); return x;
    }function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    -->
    </script>
    </HEAD><BODY marginheight="0" marginwidth="0" background="images/back.gif" leftmargin="3" topmargin="2" bgproperties="fixed">
    <table id=UserList width="100%" border="0" cellspacing="0" cellpadding="5" >
    </table>
    <iframe id=FlashFrame frameborder=0 height=0 name=flash noresize scrolling=no src="myiframe.htm" width=0></iframe>
    <div id="item"><a href="javascript:void(0)" onMouseDown="okscroll=true; godown=false; MM_swapImage('up','','images/scrollup1.gif',1)" onMouseUp="okscroll=false;MM_swapImgRestore()" style="cursor:default"><img name="up" border="0" src="images/scrollup.gif" width="18" height="18"></a> 
    <P>&nbsp;</P>
    <P>&nbsp;</P>
    <P>&nbsp;</P>
    <P>&nbsp;</P>
    <P>&nbsp;</P>
      <a href="javascript:void(0)" onMouseDown="okscroll=true; godown=true;MM_swapImage('down','','images/scrolldown1.gif',1)" onMouseUp="okscroll=false;MM_swapImgRestore()" style="cursor:default"><img name="down" border="0" src="images/scrolldown.gif" width="18" height="18"></a>
    </div>
    </BODY>
    </html>----------------myiframe.htm------------------------------<HTML>
    <HEAD>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel=stylesheet type="text/css" href="css/style.css">
    <script language=javascript>
    <!--
      setTimeout("location.reload()",8000);
    -->
    </script>
    </HEAD>
    <BODY>
    <script language=javascript>if(parent.document.all.UserList.rows.length>0){parent.document.all.UserList.deleteRow();};newRow =parent.document.all.UserList.insertRow(parent.document.all.UserList.rows.length);newRow.insertCell(0).innerHTML="<table id=ShowUserList width=100% border=0 cellspacing=0 cellpadding=1><a href=javascript:opensend('send.asp?ToUserID=470') class=as01><IMG SRC='../../images/ecall/face/face03.gif' Border=0>系统管理员</a><br><a href=javascript:opensend('send.asp?ToUserID=475') class=as01><IMG SRC='../../images/ecall/face/face03.gif' Border=0>超级管理员</a><br></table>";</script>
    <script language=javascript>parent.document.all.TAB_INF.rows(0).cells(0).innerHTML='<IMG SRC=../../images/ecall/message.gif>';</script>
    </BODY>
    </HTML>