4.Element 使用

Element.show(element,…) Element.hide(element,…) 可以根据元素 id 来显示和隐藏元素。

<html>

    <head>

        <title></title>

        <%=javascript_include_tag( :defaults )%>

        <script type ="text/javascript">

            function show(){

                Element.show('mydiv');

            }

            function hide(){

                Element.hide('mydiv');

            }

        </script>

    </head>

    <body>

        <input type ="button" value="show" onclick="show();"/>

        <input type ="button" value="hide" onclick="hide();"/>

        <div id ="mydiv" style="display:none;">

            Test Element

        </div>

    </body>

</html>

 

Element.remove(element) 根据元素 id 删除元素。

<html>

    <head>

        <title>Element.remove</title>

        <%=javascript_include_tag( :defaults )%>

        <script type ="text/javascript">

            function remove(){

                Element.remove('mydiv');

            }

        </script>

    </head>

    <body>

        <input type ="button" value="remove" onclick="remove();"/>

        <div id ="mydiv">

            Test Element

        </div>

    </body>

</html>