2015-04-24 22 views
0

我正試圖讓更改事件在下拉菜單上交換。如果有人隱藏,我希望它顯示值匹配時,反之亦然。目前,一旦隱藏,價值改變,它仍然隱藏。請幫忙。切換不適合我。jQuery的點擊更改事件顯示,交換

<label for="filter-select"> Issue Type: </label> 
<select class="filter" id="filter-select" name="filtering"> 
    <option selected="selected">Any</option> 
    <option value="incident">Incidents</option> 
    <option value="feature">Feature Requests</option> 
</select> 
$(".sort > tr > td:nth-child(1)").each(function(){ 
    var textid = $(this).text(); 
    $(this).attr('id', textid); 
    var id = $(this).attr('id'); 
    $(".sort > tr").each(function(){ 
var ide = $(this).children('td:nth-child(1)').attr('id'); 
$(this).attr('id', ide); 

}); 

var username = "[email protected]" 
var password = "DpcMixcolt12!!" 
var formurl = "/api/v2/requests/"+id+".json)"; 
function make_base_auth(user, password) { 
var tok = user + ':' + password 
var hash = btoa(tok); 
return "Basic " + hash; 
}  

$.ajax({ 
type: 'GET', 
url: formurl, 
datatype: "json", 
beforeSend: function (xhr) { 
xhr.setRequestHeader('Authorization',make_base_auth(username, password)); 

}, 
success: function (result) { 

$.each(result, function(i, value) { 

$('.filter').change(function() { 
    if ($(this).val() =='any') { 
     $('.sort > tr').each(function() { 
      $(this).show(); 
     }); 
    } 

    if ($(this).val() === 'incident') { 
     $('.sort > tr').each(function() { 
      if (value.ticket_form_id == '59229' & value.id == $(this).attr('id')) { 
       console.log('incident', $(this).attr('id')); 
       $(this).toggle(); 
      } 
     }); 
    } 
    else if ($(this).val() === 'feature') { 
     $('.sort > tr').each(function() { 
      if (value.ticket_form_id == '39365' & value.id == $(this).attr('id')) { 
       console.log('new feature', $(this).attr('id')); 
       $(this).toggle(); 
      } 
     }); 
    }  
    }); 
    }) 
} 
}); 
}); 

enter image description here

+0

什麼是「一」,它是一個選擇框,你指的是「一個」? –

+0

請注意,當元素隱藏時,javascript不會在這些元素上運行 – vinayakj

+0

當我選擇功能請求時,它會隱藏滿足if語句要求的故障單,但如果在選擇功能請求後選擇故障單,它們將保持隱藏狀態。我希望他們交換回來。這個想法是隻在事件選項被選中時才顯示事件,而在選擇新功能選項時只顯示新功能。 –

回答

0

我猜你所想的選擇選項切換不會工作。我試圖隱藏選擇後,它被選中,並顯示它回來時,選擇其他選項

+0

這是隱藏的選項,我只是希望它隱藏返回的數據。 –

+0

您和條件&是錯誤嘗試&&在condiy –

+0

請不要規避質量過濾器。要麼在你的答案中包含小提琴的代碼,要麼根本不鏈接到小提琴。 – BoltClock