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

JQuery实现通过点击标题切换字体

时间:2017-03-30 15:29:38      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:添加   bsp   his   logs   函数   jquer   cursor   style   切换   

这个主要通过判断被点击的元素的子元素中是否包含了b元素来进行字体的切换,其中wrapInner函数是为了在$author元素的内部添加b标签。

切换回正常字体是通过将内容转化为纯文本形式,再替换元素内容来实现的。

$(‘#f-author‘).css(‘cursor‘,‘pointer‘);
$(‘#f-author‘).click(function(event){
    var $author = $(this);
    if(!$author.children().is(‘b‘)){//子元素没有b            
        $author.wrapInner(‘<b></b>‘);//包含在$author里面
    }
    else{
        var text = $author.text(); //纯文本
        $author.text(text);
    }
});

 

JQuery实现通过点击标题切换字体

标签:添加   bsp   his   logs   函数   jquer   cursor   style   切换   

原文地址:http://www.cnblogs.com/pfr-blog/p/6646321.html

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