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>

 

相关文章