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

相关推荐
前端熊猫2 天前
jQuery AJAX、Axios与Fetch
ajax·okhttp·jquery
二月垂耳兔79815 天前
jQueryHTML与插件
前端·jquery
Enti7c20 天前
用 HTML、CSS 和 jQuery 打造多页输入框验证功能
css·html·jquery
ElasticPDF-新国产PDF编辑器20 天前
HTML && jQuery PDF Annotation plugin library free online API examples
pdf·html·jquery
Enti7c21 天前
前端表单输入框验证
前端·javascript·jquery
ElasticPDF-新国产PDF编辑器21 天前
HTML && jQuery 项目 PDF 批注插件库在线版 API 示例教程
pdf·html·jquery
Enti7c22 天前
数据一键导出为 Excel 文件
前端·javascript·excel·jquery
小旋风0123424 天前
封装可拖动弹窗(vue jquery引入到html的版本)
vue.js·html·jquery
Json_1 个月前
jQuery选项卡小练习
前端·深度学习·jquery
Json_1 个月前
jQuery打字机小练习
前端·深度学习·jquery