无涯教程-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

相关推荐
wno7041 天前
node.js中使用jquery
前端·node.js·jquery
鶴哥只手遮天10 天前
jQuery 4.0 源码架构与工程实践-第 01 章 · 全景与工程结构:一个 20 岁库的自省
前端·javascript·jquery
鶴哥只手遮天11 天前
jQuery 4.0 源码架构与工程实践-第 10 章 尺寸、几何与显隐
前端·javascript·jquery
变与不变80612 天前
jQuery细节以及使用应用场景
前端·javascript·jquery
王大师王文峰16 天前
HTML 入门到进阶:语义化标签、表单与多媒体一篇打通【语义化布局、表单校验、video/audio、Canvas、无障碍与 SEO】
前端·css·node.js·html·css3·jquery·html5
变与不变80619 天前
jQuery 核心语法与 jQuery AJAX
前端·ajax·jquery
ycydynq19 天前
django用Bootstrap 模态框 在同一页面实现增删改查
django·bootstrap·jquery
传人once1 个月前
选择文件按钮样式如何美化
前端·html·css3·jquery·html5
传人once1 个月前
网页文字滚动效果如何做
前端·css·html·jquery·html5
传人once1 个月前
多图片上传预览功能如何写
前端·css·html·jquery·html5