2011-09-23 63 views
0

我有一個多選,第一個選項爲「全部」和其他選項。我想要做的是當選擇「全部」時,A,B,C,D將取消選擇,但選擇A,B,C,D,選擇「全部」。在移動Safari中的多個選擇

HTML:

<select name="filter" id="filter-select" multiple="multiple"> 
    <option id="All" value="All">All</option> 
    <option id="A" value="A">A</option> 
    <option id="B" value="B">B</option> 
    <option id="C" value="C">C</option> 
    <option id="D" value="D">D</option> 
    <option id="E" value="E">E</option> 
    <option id="F" value="F">F</option> 
    <option id="G" value="G">G</option> 
    <option id="H" value="H">H</option> 
</select> 

的JavaScript:

function UnselectAll() { 
    var select = document.getElementById('filter-select'); 

    if(select.options[select.selectedIndex].id != 'All') { 
     select[0].selected = false; 
    } else { 
     for(var x = 0; x < select.length; x++) { 
      select[x].selected = false; 
     } 
    } 
} 
document.getElementById('filter-select').addEventListener('change', UnselectAll, false); 

我的問題是,當你選擇的選項,他們不會,直到你選擇框內滾出視圖中顯示的去除選擇。

請協助。

感謝

回答

0

小錯字 - 你與其他選項一起清0,這樣一個變化不大將幫助:

for(var x = 1; x < select.length; x++) {