2013-05-08 57 views
0

我有兩個下拉選擇。一個叫做 學科,另一個叫做MensLevels 它們都基於第一個select的值共享相同的ID ,我該如何隱藏第二個select? 這裏是我的代碼:jquery隱藏兩下拉選擇

$("select[name=Disciplines]").change(function() { 
     if ($(this).val() == 'Acro') { 
       var PID = $(this).attr('id'); 
       $('td:nth-child(6).attr("id") == "' + PID + '"').hide(); 
      } 
    }); 
+3

我沒有看到一個問題。 – kapa 2013-05-08 14:31:03

+1

你可以添加你的HTML嗎? – 2013-05-08 14:32:58

+0

我想我們需要比這更多的代碼,你的html在哪裏,以及「我想隱藏第二個選擇」是什麼意思? – pythonian29033 2013-05-08 14:34:09

回答

1
$("select[name=Disciplines]").change(function() { 
    if ($(this).val() == 'Acro') { 
     $('select[name=MensLevels][id="' + this.id + '"]').hide(); 
    } 
}); 
+0

這個答案應該標記爲讓我看起來像個傻瓜 – pythonian29033 2013-05-08 14:46:14

1

首先在選擇爲.change事件的所有值「家法」的必須有周圍的引號,像這樣:「中選擇[名稱=‘學科’]」,而不是這樣,你有它不帶引號:「中選擇[名稱=學科]」

這會是你在找什麼?:

$("select[name='Disciplines']").change(function() { 
    if ($(this).val() == 'Acro') { 
      var PID = $(this).attr('id'); 


      $('#' + PID).each(function(index){ 
       if(index > 0 && $(this).attr("name") != "Disciplines"){ 
        $(this).hide(); 
        return true; 
       } 
      }); 
     } 
});