jQuery 中的 Wrapall

首页 / jQuery入门教程 / jQuery 中的 Wrapall

wrapAll(Html)方法将匹配集合中的所有元素包装到单个包装元素中。

Wrapall-html - 语法

selector.wrapAll( html )

下面是此方法使用的所有参数的说明

无涯教程网

  • html    -  动态创建并环绕每个目标的HTML字符串。

Wrapall-html - 示例

下面是一个简单的示例,一个简单的示例说明了该方法的用法。这将用一个新的正方形-包装所有的正方形

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/dom-wrapall-html.html

来源:LearnFk无涯教程网

<html>
   <head>
      <title>The jQuery Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
            $("div").click(function () {
               var content="<div class='div'></div>";
               $("div").wrapAll( content );
            });
         });
      </script>
		
      <style>
         .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
      </style>
   </head>
	
   <body>
      <p>Click on any square below to see the result:</p>
		
      <div class="div" id="destination">THIS IS TEST</div>
      <div class="div" style="background-color:blue;">ONE</div>
      <div class="div" style="background-color:green;">TWO</div>
      <div class="div" style="background-color:red;">THREE</div>
   </body>
</html>

这将产生以下输出-

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

软件工程之美 -〔宝玉〕

A/B测试从0到1 -〔张博伟〕

React Hooks 核心原理与实战 -〔王沛〕

超级访谈:对话张雪峰 -〔张雪峰〕

朱涛 · Kotlin编程第一课 -〔朱涛〕

林外 · 专利写作第一课 -〔林外〕

手把手带你搭建推荐系统 -〔黄鸿波〕

AI绘画核心技术与实战 -〔南柯〕

结构写作力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)