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

相关推荐
不要再敲了21 小时前
JavaScript与jQuery:从入门到面试的完整指南
javascript·面试·jquery
joan_854 天前
jquery在文心智能体平台使用API方式部署智能体-AI客服
前端·人工智能·ai·jquery
携欢5 天前
PortSwigger靶场之DOM XSS in jQuery selector sink using a hashchange event通关秘籍
前端·jquery·xss
长城202411 天前
jQuery的$.Ajax方法分析
ajax·jquery·异步提交
♡喜欢做梦18 天前
jQuery 从入门到实践:基础语法、事件与元素操作全解析
前端·javascript·jquery
盛夏绽放23 天前
jQuery 知识点复习总览
前端·javascript·jquery
艾小码1 个月前
告别jQuery:2025年原生DOM操作最佳实践
前端·javascript·jquery
合作小小程序员小小店1 个月前
web网站开发,在线%射击比赛成绩管理%系统开发demo,基于html,css,jquery,python,django,model,orm,mysql数据库
python·mysql·django·jquery·html5
合作小小程序员小小店1 个月前
web安全开发,在线%射击比赛管理%系统开发demo,基于html,css,jquery,python,django,三层mysql数据库
css·mysql·django·html·jquery
Sy_planA1 个月前
介绍一下jQuery的AJAX异步请求
ajax·okhttp·jquery