2012-09-30 16 views
-1

我幾乎用樣機完成,我需要在這一個小竅門:使錯誤的div .fadeOut當用戶選擇一個「合適」的價值

<form> 
    <div class="line"> 
     <label>Embarque:</label> 
     <select> 
     <option value="first">Selecione a Estação</option> 
      <option value="second" >Trianon-Masp | Linha 2 - Verde</option> 
     </select> 
     <div class="error">Selecione a estação de embarque</div> 
    </div><!-- end line --> 
</form> 

當用戶選擇第二個選項,.error將fadeOut();任何人都知道如何推出它?

+0

大聲笑,兩次-1票,沒有人敢解釋它:) –

回答

2

對於<select>標籤給出id

<select id="lineSelect"> 

使用此:

$("select#lineSelect").change(function(){ 
    if ($(this).val() == "correct") 
     $(".error").fadeOut(); 
}); 

或者,你可以使用:

$(".line select").change(function(){ 
    if ($(this).val() == "correct") 
     $(".error").fadeOut(); 
}); 
+0

請記住,它將綁定onchange事件到頁面上的所有選擇框,並隱藏頁面上的所有錯誤,如果他們中的任何一個被更改!另外,沒有值'正確' –

+0

我知道。也會用HTML更新答案。 :)謝謝@ZathrusWriter –

+0

。.change()是環形的東西,像一個魅力,工作感謝隊友! – fernandofleury

1

肯定的:

$('div.line select').on('change', function() { 
    if (this.value == this.options[1].value) { 
     $(this).next('div.error').hide('slow'); 
    } 
}); 

jsFiddle example here

+1

工作得非常好,但.change似乎流動更容易一些。謝謝朋友! – fernandofleury