waterwalk

导航

 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="./lib/d3.js"></script>
    <script src="./lib/jquery.js"></script>
    <style>
    .red{
        color:red;
    }
    </style>
</head>
    <body>
        <div>你我他</div>
        <div>你我他</div>
        <div>你我他</div>
        <div>你我他</div>

        <script>
            $('div').each(function(){
                var $this = $(this);
                var text = $this.text();
                var start = '你';
                var num = text.indexOf(start);
                console.log(num);
                if(num != -1){
                     text =text.replace(start,'<b class ="red">wo</b>');
                    $this.html(text);
                };
                
            });
            setTimeout(function(){
                $('.red').each(function(){
                    var $this = $(this);
                    var text = $this.text();
                    $this.replaceWith(text);
                })
            },3000)
        </script>
    </body>
</html>

replaceWith();将选中的标签包括标签进行替换。

posted on 2016-11-02 15:47  waterwalk  阅读(160)  评论(0)    收藏  举报