【问题标题】:Get css class list from style tag从样式标签中获取 css 类列表
【发布时间】:2018-12-17 22:05:18
【问题描述】:

我想获取样式标签中使用的类的列表,并稍后附加到下拉列表中。我的 ASPX 页面中有以下代码

<style id="pageStyleCss" type="text/css">
  body {
    color: black;
  }
  
  .testclass1 {
    height: 100px;
  }
  
  .testclass2 {
    height: 100px;
    color: red;
  }
  
  #testid {
    color: black;
  }
</style>


var resultarray= [];

var a = $('#pageStyleCss').html();

while (a.indexOf('{') != -1) {

resultarray.push(a.substring(0, a.indexOf('{')));

a = a.substring(a.indexOf('}') + 1);
}
The output I want is:
Class list :  testclass1,testclass2 

【问题讨论】:

  • 我问的不是这个。

标签: jquery html css asp.net


【解决方案1】:
Below code helped me getting my requirement.   

  var resultarray = [];
        var a = $('#pageStyleCss').html();
        if (a != undefined) {
            while (a.indexOf('{') != -1) {
                resultarray.push(a.substring(0, a.indexOf('{')));
                a = a.substring(a.indexOf('}') + 1);
            }
        }
        var i, option = "<option value=''></option>"
        for (i = 0; i < resultarray.length; ++i) {
            if (resultarray[i].indexOf('.') > -1) {
                option += '<option value="' + resultarray[i].trim().replace('.', '') + '">' + resultarray[i].trim().replace('.', '') + '</option>';
            }
        }

【讨论】:

    猜你喜欢
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 2012-07-21
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多