1. <style>
  2. .s1{color: rebeccapurple;font-size: 25px;}
  3. .s2{color: red;}
  4. .s3{color: blue;}
  5. .s4{color:yellow;}
  6. </style>
  7. <div id="div">
  8. <span>1</span>
  9. <span>2</span>
  10. <span>1</span>
  11. <span>3</span>
  12. <span>1</span>
  13. </div>
  14. <script>
  15. var div=document.getElementById('div');
  16. var child=div.children;
  17. var ar=[];
  18. for(i=0;i<child.length;i++){
  19. var n=child[i].innerHTML;
  20. ar.push(n);
  21. }
  22. for(i=0;i<ar.length;i++){
  23. child[i].className='s'+ar[i];
  24. }
  25. </script>

 

版权声明:本文为no000000原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/no000000/p/12855709.html