能不能给个例子,就假如一个网页上有3个DIV,现在要改变其中一个DIV的值,一个DIV的位置,能够给个例子

解决方案 »

  1.   

    请看代码
    eg:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head><body>
    <form method=post action="">
    <DIV ALIGN="left" id="div1"style="width:100;height:200;background-color=red;">dd</DIV>
    <input type="button" value="change" onclick="getObjectById('div1').innerText='hello world!';
    getObjectById('div1').style.backgroundColor='gray';">
    </form>
    <script language="JavaScript">
    <!--
    function getObjectById(id)
    {
      if (typeof(id) != "string" || id == "") throw(new Error(-1, '传到函数 getObjectById 里的参数不对!'));
      if (document.all) return document.all(id);
      try {return document.getElementById(id);} catch(e){ return eval(id);}
    }
    //-->
    </script>
    </body>
    </html>
      

  2.   

    <div id="division1"></div>
    <div id="division2"></div>
    <div id="division3"></div>
    <input type="text" onkeyup="document.getElementById('division2').innerHTML = this.value;">
    <input type="button" onclick="divmove();" value="move div">
    <script language="javascript">
    function divmove()
    {
    var t = 100;
    var l = 300; document.getElementById('division2').style.position = 'absolute';
    document.getElementById('division2').style.top = t;
    document.getElementById('division2').style.left = l;
    }
    </script>
      

  3.   

    先打开一个网页,然后在地址栏中输入以下代码,然后回车就行了。
    javascript:document.body.contentEditable='true';document.designMode='on';void(0);
      

  4.   

    谢谢各位的回答,我是想这样,在一个页面上有很多个DIV,我用鼠标点击,点中一个DIV,就弹出一个编辑框,然后输入修改值,然后再修改页面的内容.还有就是用鼠标控制DIV的移动.
        还有就是
    <!--
    function getObjectById(id)
    {
      if (typeof(id) != "string" || id == "") throw(new Error(-1, '传到函数 getObjectById 里的参数不对!'));
      if (document.all) return document.all(id);
      try {return document.getElementById(id);} catch(e){ return eval(id);}
    }
    //-->
    其中<!--和//-->是什么意思,加和不加有什么区别了?
      

  5.   

    “<!—”和标识符”—>”之间是可以在一些不支持JAVASCIRPT的浏览器里隐藏JAVASCRIPT。在“//”后的是可被忽略的注释。
    这里要注意的是:使用上述两种注释都必须在同一行内完成,如要另外提行写注释,应另外在相应的行加上这两种标识符的一种,不然,系统会提示出错信息。
      

  6.   

    用div.innerHtml来修改就可以了。
      

  7.   

    为什么有时候 div.innerHtml 是空的了?