我有这个HTML页面:
<div class="rigaEven">
<div class="col1">
<p class="room">AULA B</p>
<p class="where">XXX</p>
</div>
<div class="col2 half">
<p class="when">09:00 - 11:00</p>
</div>
<div class="col3">
<p class="what">WHAT.</p>
<p class="type">Insegnamento</p>
<p class="who">PROF</p>
</div>
</div>
<div class="rigaOdd">
<div class="col1">
<p class="room">AULA WHAT</p>
<p class="where">XXX</p>
</div>
<div class="col2 half">
<p class="when">09:00 - 11:00</p>
</div>
<div class="col3">
<p class="what">KKK</p>
<p class="type">Insegnamento</p>
<p class="who">PROF</p>
</div>
</div>
<div class="rigaEven">
<div class="col1">
<p class="room">AULA MAGNA</p>
<p class="where">XXX</p>
</div>
<div class="col2 half">
<p class="when">09:00 - 11:00</p>
</div>
<div class="col3">
<p class="what">SSS</p>
<p class="type">Insegnamento</p>
<p class="who">PROF</p>
</div>
</div>
<div class="rigaOdd">
<div class="col1">
<p class="room">AULA D</p>
<p class="where">XXX</p>
</div>
<div class="col2 half">
<p class="when">09:00 - 13:00</p>
</div>
<div class="col3">
<p class="what">LAB</p>
<p class="type">Laboratorio</p>
<p class="who">PROF</p>
</div>
</div>
在我的Android Activity中,我隐藏并显示div(rigaEven,rigaOdd) 基于p的值(class&#34; what&#34;)这是方法:
public String showActivity(String filter){
return "javascript:(function(){" +
" $( \".rigaEven\").hide();" +
" $( \".rigaOdd\").hide();";+
" $( \".rigaEven:contains("+filter+")\" ).show();" +
" $( \".rigaOdd:contains("+filter+")\" ).show();" +
" $( \".what:contains("+filter+")\" ).show();"+
"})()";
}
但是,如果是p级的房间并且包含&#34; AULA WHAT&#34; p类还包含它&#34; WHAT&#34;两者都是可见的,但我希望你只能看到在大厅里传递的字符串是什么,我该怎么办?
答案 0 :(得分:0)
很遗憾,您无法使用选择器执行此操作(匹配确切内容),因此您需要使用filter
函数。参见例如this post
例如,对于rigaEven
元素,您需要:
$(".rigaEven").filter(
function(){
return "filter" === $(this).text();
}
).show();
当然,将其编码为字符串非常有趣。以下是该示例的(未经验证的)尝试:
"$(\".rigaEven\").filter(function(){return \"" + filter + "\" === $(this).text();}).show();"
我将剩下的转换乐趣留给您。 : - )