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>