jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
wrap(elem) |
wrap(elem)
把所有匹配的元素用其他元素的结构化标记包装起来。 这种包装对于在文档中插入额外的结构化标记最有用,而且它不会破坏原始文档的语义品质。 这个函数的原理是检查提供的第一个元素并在它的代码结构中找到最上层的祖先元素--这个祖先元素就是包装元素。 当HTML标记代码中的元素包含文本时无法使用这个函数。 因此,如果要添加文本应该在包装完成之后再行添加。 返回值:jQuery 参数:
示例: $("p").wrap( document.getElementById('content') ); HTML 代码: <p>Test Paragraph.</p><div id="content"></div> 结果: <div id="content"><p>Test Paragraph.</p></div> Wrap all matched elements with a structure of other elements. This wrapping process is most useful for injecting additional stucture into a document, without ruining the original semantic qualities of a document. This works by going through the first element provided and finding the deepest ancestor element within its structure - it is that element that will en-wrap everything else. This does not work with elements that contain text. Any necessary text must be added after the wrapping is done. Return value: jQuery
Example: $("p").wrap( document.getElementById('content') );Before: <p>Test Paragraph.</p><div id="content"></div>Result: <div id="content"><p>Test Paragraph.</p></div> |