码迷,mamicode.com
首页 > Web开发 > 详细

JQuery的wrap用法

时间:2017-07-13 10:26:55      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:return   png   参考   his   man   nbsp   this   function   color   

wrap是包裹元素的作用,比如我想在img外面包裹一个a标签时,可以这样写法:

$(function(){
    $(‘img‘).wrap(function(){
        return ‘<a href="‘ + this.src + ‘" title="点击查看原图" target="_blank"></a>‘;
    })
});

此时在前端渲染出来的HTML如下所示:

<a href="http://images2015.cnblogs.com/blog/417876/201707/417876-20170712170222118-748566468.png" title="点击查看原图" target="_blank">
  <
img src="http://images2015.cnblogs.com/blog/417876/201707/417876-20170712170222118-748566468.png" alt="">
</
a>

 

参考:

http://www.w3school.com.cn/jquery/manipulation_wrap.asp

JQuery的wrap用法

标签:return   png   参考   his   man   nbsp   this   function   color   

原文地址:http://www.cnblogs.com/EasonJim/p/7158486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!