Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个名为“type”的键数组。数组的名称是“th”标签的类名。我想通过使用“th”标签的类名来获取这个数组值。有没有可能做到这一点......
<script> var type= [{sym :"1" ,desc: "one"}, {sym:"2" ,desc:"two"},{sym: "3" ,desc:"three"}]; </script> <html> <body> <table> <th class="type"> </table> </body> </html>
您可以将数组(或多个数组)存储在一个对象中,使用类名作为键:
var arrays = { type: [{sym: "1", desc: "one"}, {sym: "2", desc: "two"}, {sym: "3", desc: "three"}] };
然后您可以稍后简单地使用类名来获取数组:
var typeArray = arrays[$("th").attr("class")];