我有兩個HTML選擇下拉菜單:基於jQuery的另一個選擇的值動態改變選擇選項
<select name="county" id="county">
<option value="Any">Any County</option>
<option value="Lancaster County">Lancaster County, PA</option>
<option value="Berks County">Berks County, PA</option>
<option value="Montgomery County">Montgomery County, PA</option>
<option value="Dauphin County">Dauphin County, PA</option>
<option value="Adams County">Adams County, PA</option>
<option value="Chester County">Chester County, PA</option>
<option value="Lebanon County ">Lebanon County, PA</option>
<option value="Delaware County">Delaware County, PA</option>
<option value="York County">York County, PA</option>
<option value="New Castle County">New Castle County, DE</option>
<option value="Orange County">Orange County, NY</option>
</select>
<select name="township" id="township">
<option value="Any">Any Township</option>
<option value="Bethel Township">Bethel Township</option>
<option value="Borough of Cornwall">Borough of Cornwall</option>
<option value="Concord Township">Concord Township</option>
<option value="Cumberland Township">Cumberland Township</option>
<option value="Derry Township">Derry Township</option>
<option value="East Brandywine Township">East Brandywine Township</option>
<option value="East Hempfield Township">East Hempfield Township</option>
<option value="Kennett Township">Kennett Township</option>
<option value="Lower Merion Township">Lower Merion Township</option>
<option value="New Castle County">New Castle County</option>
<option value="Penn Township">Penn Township</option>
<option value="Springfield Township">Springfield Township</option>
<option value="Town of Warwick">Town of Warwick</option>
<option value="Township of Spring">Township of Spring</option>
<option value="Treddyfrin Township">Treddyfrin Township</option>
<option value="Warwick Township">Warwick Township</option>
<option value="West Bradford Township">West Bradford Township</option>
<option value="West Donegal Township">West Donegal Township</option>
<option value="West Lampeter Township">West Lampeter Township</option>
<option value="West Vincent Township">West Vincent Township</option>
<option value="West Whiteland Township">West Whiteland Township</option>
<option value="York Township">York Township</option>
</select>
我需要一個jquery腳本,執行以下操作:
當選擇了一個特定的#county option
,僅顯示適當的#township options
。例如:
如果選擇了蘭開斯特縣選項中,只有西多尼戈爾鄉,西蘭彼得鄉,東Hempfield鄉,將顯示沃裏克鎮選項。
或者,如果選擇了伯克斯縣選項,只有春鄉將被顯示。
我試過的jQuery代碼等例子來使該功能的工作,似乎無法得到它做什麼,我需要。我有一點jquery/javascript的知識,所以任何幫助將不勝感激。
您忘記發佈了javascript已經嘗試過 – FreshPro
看看http://www.appelsiini.net/projects/chained它應該適合您 –
如何使用本網站的搜索功能? –