Heim  >  Artikel  >  Web-Frontend  >  jQuery 如何 根据 value 获得 class_html/css_WEB-ITnose

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

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

看清楚,不是要类选择器取得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>





没分了...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn