jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
wrap(elem) |
wrap(html)把所有匹配的元素用其他元素的结构化标记包装起来。 这种包装对于在文档中插入额外的结构化标记最有用,而且它不会破坏原始文档的语义品质。 这个函数的原理是检查提供的第一个元素(它是由所提供的HTML标记代码动态生成的),并在它的代码结构中找到最上层的祖先元素--这个祖先元素就是包装元素。 当HTML标记代码中的元素包含文本时无法使用这个函数。因此,如果要添加文本应该在包装完成之后再行添加。 返回值:jQuery 参数:
示例: $("p").wrap("<div class='wrap'></div>"); HTML 代码: <p>Test Paragraph.</p> 结果: <div class='wrap'><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 (which is generated, on the fly, from the provided HTML) and finds 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("<div class='wrap'></div>");Before: <p>Test Paragraph.</p>Result: <div class='wrap'><p>Test Paragraph |