我现在有个select控件,因为要隐藏部分内容,用了clip:rect,但位置必须是要绝对的。
现在这个控件在一个有垂直滚动条的div中,结果滚动条一滚,select控件就留在了原地。
请问如何把控件做成可以动的?(jsp+js) 谢谢!!!

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    var selectTop = 0;
    window.onload = function(){
    selectTop = document.getElementById("s1").style.top;
    };
    function on_scroll(obj){
    document.getElementById("s1").style.top = obj.scrollTop + parseInt(selectTop.replace("px","")) +"px";
    }
    </script>
    </head><body>
    <div id=d1 style="position:absolute;width:100px;height:100px;overflow:auto;" onscroll="on_scroll(this)">1<br/>1<br/>1
    <select id=s1 style="position:absolute;top:10px;left:40px"><option>1</option></select>
    <br/>1<br/>1<br/>1<br/>
    1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
    </div>
    </body></html>
      

  2.   


    谢谢出手帮忙,但我想要的效果是select在div中就像其他控件一样随滚动条的滚动而滚动,位置设成绝对是为了clip:rect的需要 ,听起来是有些矛盾。或者还有什么其他的办法实现这样的效果么?