1

私はテーブルを持っています。TD 内 (内) をクリックすると、内部にいくつかの div を含む非表示の div を表示する必要があります。その隠しコンテナ内の各 div にはテキスト値があります。クリックした TD に対応する値を選択する必要があります。

JS

$(".clickme").click(function(){
    $("#hiddenDiv").hide().fadeIn(200);

    if ($(this).text() == $("#hiddenDiv div").text()) {
         //  HOW DO I SELECT THAT DIV? 
         // matched div .css("color", "red");  
    }

});

HTML

<table id="myTbl">
<tr>
  <td></td>
  <td class="clickme">Left</td>  
</tr>
</table>

<div id="hiddenDiv" style="display:none">
  <div>Straight</div>
  <div>Left</div>
  <div>Right</div>
</div>
4

3 に答える 3

3

:containsを使用して正しいものを選択します。

$("#hiddenDiv div:contains(" + $(this).text() + ")")
于 2012-05-17T21:48:11.137 に答える
1

デモ jsBIn

$(".clickme").click(function(){

    var thisText = $(this).text();
    var $targetEl =  $('#hiddenDiv > div:contains('+thisText+')');

    if( $targetEl.length > 0 ){  // if exists
          $("#hiddenDiv").hide().fadeIn(200);
         $targetEl.css({color:'red'});
    }

});
于 2012-05-17T21:55:23.133 に答える
0
$(".clickme").click(function() {
    $("#hiddenDiv").hide().fadeIn(200);
    var $this = $(this);
    $("#hiddenDiv div").filter(function() {
        return $(this).text() == $this.text();
    }).css("color", "red").show();
});​
于 2012-05-17T21:48:42.637 に答える