无涯教程-jQuery - wrapInner( html )方法函数

wrapInner(html)方法使用HTML结构包装每个匹配元素(包括文本节点)的内部子内容。

wrapInner( html ) - 语法

复制代码
selector.wrapInner( html )

这是此方法使用的所有参数的描述-

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

wrapInner( html ) - 示例

以下是一个简单的示例,简单说明了此方法的用法。这将选择所有分区,并在单击的一个正方形的内容周围包裹一个粗体标签-

复制代码
<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="<b></b>";
               $(this).wrapInner( 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>

这将产生以下输出-

参考链接

https://www.learnfk.com/jquery/dom-wrapinner-html.html

相关推荐
传人once1 天前
选择文件按钮样式如何美化
前端·html·css3·jquery·html5
传人once4 天前
网页文字滚动效果如何做
前端·css·html·jquery·html5
传人once5 天前
多图片上传预览功能如何写
前端·css·html·jquery·html5
传人7 天前
网页文字滚动效果如何做
前端·javascript·jquery
研☆香10 天前
jQuery + Swiper.js 实现动态渲染轮播图
前端·javascript·jquery
刺客码24 天前
Layui 表格固定列行高错位问题解决方案
前端框架·layui·jquery·web
এ慕ོ冬℘゜1 个月前
前端实战:基于jQuery递归实现通用树形组织菜单(可直接复用)
前端·javascript·jquery
零域码客1 个月前
一文掌握 jQuery + Flask 全栈核心知识点(前端交互 + 后端接口 + 前后端联调)
前端·python·ajax·flask·jquery·前后端联调·web全栈
暖焰核心1 个月前
C++模板进阶——特化全解
javascript·c++·jquery
喵本喵叁肆1 个月前
06-M6-部门过滤与综合研判-从问答机到研判助手
前端·javascript·jquery