通过JS为HTML标签添加样式
作者:互联网
1、直接根据id赋予类或移除类;
<style> .tab-close{ cursor: not-allowed; } .atab-close{ pointer-events: none; } </style> <li id="tab2"><a id="atab2" href="#tab_2" data-toggle="tab">1</a></li> //js代码 <script> $("#tab2").addClass("tab-close"); $("#atab2").addClass("atab-close"); $("#tab2").removeClass("tab-close"); $("#atab2").removeClass("atab-close"); </script>View Code
2、动态为元素赋予类或移除类
var element = document.getElementById(ys_id); element.classList.add("focusColor");//给ys_id添加类focusColor的样式 element.parentNode.classList.add("focusColor");//给ys_id的父元素添加类focusColor的样式View Code
3、select2中设置下拉框的样式
$('#ylfkfs').select2({ data:${ylfkfs}, language : "zh-CN", multiple:false, minimumResultsForSearch: -1 }); var span_select = document.getElementById("select2-ylfkfs-container").parentNode; span_select.style.border = "0px"; document.getElementById("select2-ylfkfs-container").style.paddingLeft = "13px";View Code
参考博文:https://www.cnblogs.com/henuyuxiang/p/7423993.html
标签:ylfkfs,标签,JS,HTML,tab,select2,close,id,focusColor 来源: https://www.cnblogs.com/daytoy105/p/16655945.html