我的问题是:我用js调用DIV 并做一个判断,有一个Div 它的高度是auto的我会在里面加数据,但是我要用js做一个判断当DIV的高度达到190Px的时候就出现滚动条!!

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    <!--
    .box {background:#FFF1F1;border:1px solid #FCB1AE; height:auto}
    .box1 {height:190px; display:block; overflow-y:scroll}
    -->
    </style>
    </head><body>
    <div class="box">12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12</div>
    <div class="box">123</div>
    <script type="text/javascript">
    <!--
    function setTarCss(){
    var i,objs
    objs=document.getElementsByTagName("div");
    for(i=0;i<objs.length;i++){
    if(objs[i].offsetHeight>190){
    objs[i].className+=' box1';
    }
    }
    }
    window.onload=function(){
    setTarCss()
    }
    -->
    </script>
    </body>
    </html>
      

  2.   

    你的方法是可以用!但是不能获取div的ID 的啊 你是把所有的DIV 都改变的了啊 我只要一个 DIV 就可以了我要改的这个比如:我要改的这个的DIV的ID=“tt”;那该怎么办呢?
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    <!--
    .box {background:#FFF1F1;border:1px solid #FCB1AE; height:auto}
    .box1 {height:190px; display:block; overflow-y:scroll}
    -->
    </style>
    </head><body>
    <div class="box" id="demo">12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12<br />12</div>
    <div class="box">123</div>
    <script type="text/javascript">
    <!--
    function setTarCss(){
        var i,obj
        obj=document.getElementById("demo");
    if(obj.offsetHeight>190){
    obj.className+=' box1';
    }
    }
    window.onload=function(){
        setTarCss()
    }
    -->
    </script>
    </body>
    </html>