js包裹标签

当我们通过调取封装好的方法获取拼接出来的html,但是样式并不是我们想要的样式时但又不能够改变原有的样式的情况下,除了再另外写一个自己的方法,那就是把获取的html通过js调整样式

案例如下:

<script>

     $(".page").attr("class", "p_fen2");
     $(".p_fen2 span").replaceWith("<a href='" + window.location.pathname + "?page=" + $(".p_fen2 span").html() + "' class='p_fen_ac'>" + $(".p_fen2 span").html() + "</a>");
     $(".p_fen2 a").wrap("<li>");
     $(".p_fen2 li").wrapAll("<ul>");
     $(".p_fen2 a").each(function () {
         if ($(this).attr("title") == "首页") {
             $(this).text("|<");
         }
         if ($(this).attr("title") == "上一页") {
             $(this).text("<<");
         }
         if ($(this).attr("title") == "下一页") {
             $(this).text(">>");
         }
     })
</script>

解析:其中 wrap表示在每个<a>标签外添加一个<li>标签,如<li><a></a></li>

 而  wrapAll  表示的是在多个<li></li>标签外加上<ul>标签,如<ul><li></li><li></li><li></li></ul>

原文地址:https://www.cnblogs.com/97310ZT/p/8676728.html