代码之家  ›  专栏  ›  技术社区  ›  Tania Martínez

<a>展开时标记会打断样式

  •  -1
  • Tania Martínez  · 技术社区  · 6 年前

    再一次提醒我,我有这个脚本,所以当单击另一个html页面上的按钮“quadrant\u 1”时,它会更改第一个html页面上的按钮颜色,但是 我希望此操作禁用a href链接 ,为此,我有:

            var noLink = $('a')
     if(localStorage.getItem('quadrant_1', ) === 'clicked'){
        $("#btn-institucional").css({backgroundColor: "#d8d8d6"});
       $("#btn-institucional").unwrap({noLink});
    
       }
    

    移除标记,但问题是移除标记时,会破坏所有行和按钮样式

    before tag is removed

    After Tag was removed

    这是html的一个按钮

    <div class="number button col-lg-3 col-md-3 col-sm-12 col-xs-12" style="color:#ffffff; background-color:#003E8B; cursor: pointer; color: #ffffff;" id="btn-institucional">
                <a href="gobierno.html" >
    
                <p>1</p>
    
                <img src="icons/institucional.png" width= "50%">
    
                <p>Desarrollo Institucional para un Buen Gobierno</p>   
    
    
            </a></div>
    

    非常感谢您的帮助,我真的不知道为什么会发生这种情况,如果我将div与列的bootstrap类放在一起。

    1 回复  |  直到 6 年前
        1
  •  0
  •   sequel    6 年前

    我想你是想 unwrap('a') 这将删除 <div>

    您可以尝试以下操作:

     if(localStorage.getItem('quadrant_1', ) === 'clicked'){
       $("#btn-institucional").css({backgroundColor: "#d8d8d6"});
       $("#btn-institucional p").unwrap();
     }