Home  >  Article  >  Web Front-end  >  jQuery 如何 根据 value 获得 class_html/css_WEB-ITnose

jQuery 如何 根据 value 获得 class_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:521223browse

看清楚,不是要类选择器取得value!


好好学习
天天向上
...
 

是循环显示, 的class是循环编号的,现在知道某一个 的value 是 '好好学习',请问怎么得到 class ='1'


JS , Jquery 都行 


回复讨论(解决方案)

$.each($('tr td'),function(){     if($(this).text()=="天天向上")    {          alert($(this).attr("class"))    }})

$.each($('tr td'),function(){     if($(this).text()=="天天向上")    {          alert($(this).attr("class"))    }})








谢谢大牛,刚才开会去了.

<table>	<tr>		<td class="2">天天向上</td>		<td class="1">好好学习</td>	</tr></table><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script> <script type="text/javascript">alert($("td:contains('好好学习')").attr("class"));</script>

<table>	<tr>		<td class="2">天天向上</td>		<td class="1">好好学习</td>	</tr></table><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script> <script type="text/javascript">alert($("td:contains('好好学习')").attr("class"));</script>





没分了...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn