Prototype - wrap() 方法



此方法將一個元素包裝到另一個元素的內部,然後返回包裝。

語法

element.wrap(element, wrapper[, attributes]);

OR

someElement.wrap(wrapper[, attributes]);

返回值

一個 HTML 元素。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            $('test').wrap( $("bold") );
         }
      </script>
   </head>

   <body>
      <p id = "test">Formatted Paragraph</p>
      <b id = "bold">Above Paragraph should be wrapped here....<br /></b>
      <br />
      <input type = "button" value = "Click" onclick = "showResult();"/>
   </body>
</html>

輸出

prototype_element_object.htm
廣告