js遍历元素并添加属性
作者:互联网
<body>
<div id="content"> <span>好好学习</span> <span>天天向上</span> </div>
</body>
<script type="text/javascript"> $(document).ready(function(){ $("#content>span").each(function(index,item){ var str = $(item).text(); if(str.indexOf("好好学习")!=-1){ $(item).css("color","red"); } }); }) </script>
标签:function,遍历,color,好好学习,js,item,添加,str,天天向上 来源: https://www.cnblogs.com/mjtabu/p/11759785.html