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

相关推荐
王小二(海阔天空)20 小时前
个人文章合集 - 前端相关
前端·css·vue·jquery
人生の三重奏4 天前
前端——Ajax和jQuery
前端·ajax·jquery
心.c7 天前
【前端】-jQuery(带你让你深入了解学习使用jQuery)
前端·javascript·html·jquery
转角羊儿9 天前
Array.prototype.slice.call()
jquery
bin915314 天前
【油猴脚本】00010 案例 Tampermonkey油猴脚本,动态渲染表格-添加提示信息框,HTML+Css+JavaScript编写
前端·javascript·css·bootstrap·html·jquery
转角羊儿16 天前
jQuery 简介④ 参数规则与链式编程风格
jquery
空欢ོ喜ꦿ℘゜19 天前
制作论坛帖子页面
前端·javascript·html·jquery
不修×蝙蝠20 天前
后端入门 (JQuery基础) 01
笔记·后端·servlet·html·jquery
doc_wei20 天前
Java智慧云智能教育平台
java·spring·毕业设计·maven·intellij-idea·jquery·课程设计
软件技术NINI21 天前
JQuery简介 - 什么是jQuery
jquery