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

相关推荐
韩曙亮3 天前
【jQuery】jQuery 选择器 ④ ( jQuery 筛选方法 | 方法分类场景 - 向下找后代、向上找祖先、同级找兄弟、范围限定查找 )
前端·javascript·jquery·jquery筛选方法
摇滚侠4 天前
【程序员入门系列】jQuery 零基础入门到精通!Jquery 选择器 API
前端·javascript·jquery
Emma_Maria6 天前
本地项目html和jquery,访问地址报跨域解决
前端·html·jquery
清山博客7 天前
jQuery easyui 扩展datetimebox控件,增加上午、中午、下午快速选择
前端·jquery·easyui
Southern Wind9 天前
从零封装一套企业级表格组件库 - 基于 Layui 的实战教程
前端·javascript·layui·jquery
满栀58510 天前
企业后台登录页面开发
开发语言·前端·javascript·jquery
她说彩礼65万15 天前
Jquery总结
前端·javascript·jquery
ccino .17 天前
【Portswigger : DOM XSS in jQuery selector sink using a hashchange event】
前端·jquery·xss
满栀58519 天前
jQuery 递归渲染多级树形菜单
前端·javascript·jquery
w***765520 天前
JS vs jQuery:核心差异解析
开发语言·javascript·jquery