2013-07-25 38 views
0

什麼select#category指的是哪一個是元素ID? 你也可以解釋一下這個select option:selected什麼'select#category'refter to?

$("select#category").change(function() 
{ 
    if ($("select option:selected").val() == 0) { 
    $('div[id^="product_"]').hide(); 
    $('#waiting').show(); 
} 
    $('#waiting').hide(); 
    $('div[id^="product_"]').hide(); 
    if ($('div[id="product_'+$("select option:selected").val()+'"]:visible')) 
    { 
    $('div[id="product_'+$("select option:selected").val()+'"]').show(); 
    } 
} 
}); 

因此,如果「ID」參與,爲什麼它也讓選擇關鍵字呢?(因爲我覺得沒有選擇部分,它仍然是唯一的,指的是特定的元素)

回答

3

select#category
它指select元件ID爲category

select option:selected
指選定option爲S中的頁面(注意select元件:它可以返回多個元素)

在這種情況下,你可能要與$(this).val()更換$("select option:selected").val() - 它會給所選選項的值

+0

因此,如果「ID」參與它爲什麼也把選擇的關鍵字有(因爲我?認爲沒有選擇部分,它仍然是唯一的) –

+1

@SafeTobe根本不需要'select' –