이전 질문에서 Dynamic dependent select menus을 작성했습니다 : http://jsfiddle.net/Bs5Db/50/. 이것은 특정 jquery 스크립트의 HTML 버전입니다. 사용자 @jSweazy는 첫 번째 메뉴에서 새 상태를 선택할 때마다 jquery.uniform 스크립트를 업데이트해야한다고 지적했습니다. 예제의 실제 버전은 http://jsfiddle.net/Bs5Db/53/입니다. 기본 옵션이 메뉴에 비해 너무 크지 만 쉽게 고정된다는 것을 알고 있습니다.동적 종속 선택 메뉴 jQuery PHP 버전
내 문제는 실제로 스크립트의 PHP 버전을 사용한다는 것입니다. 해당 버전에서 $ .uniform.update();로 jquery.uniform을 업데이트합니다. 트릭을하지 않습니다. 사실 두 번째 메뉴는 더 이상 표시되지 않습니다. 업데이트 명령을 삽입하면됩니다.
PHP의 버전은 각 국가의 군을 데이터베이스에 쿼리와 검색됩니다
$(document).ready(function(){
function populate() {
if($('#state').val() == 'AK' || $('#state').val() == 'DC') // Alaska and District Columbia have no counties
{
$('#county_drop_down').hide();
$('#no_county_drop_down').show();
} else {
fetch.doPost('../getCounties.php');
}
}
$('#state').change(populate);
var fetch = function() {
var counties = $('#county');
return {
doPost: function(src) {
$('#loading_county_drop_down').show(); // Show the Loading...
$('#county_drop_down').hide(); // Hide the drop down
$('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case)
if (src) $.post(src, { state_code: $('#state').val() }, this.getCounties);
else throw new Error('No SRC was passed to getCounties!');
},
getCounties: function(results) {
if (!results) return;
var allCounties = $("<option value=\"All\">All Counties</option>");
counties.html(results);
counties.prepend(allCities);
counties.val("All").attr('selected',true);
$('#loading_county_drop_down').hide(); // Hide the Loading...
$('#county_drop_down').show(); // Show the drop down
}
}
}();
populate();
});
getCounties.php 잘 작동 ... 다음과 같다. 주 및 카운티는 두 개의 선택 메뉴의 이름입니다. 누군가이 스크립트의이 버전에서 카운티 메뉴를 업데이트하는 방법에 대한 조언을 나에게 줄 수 있다면 감사 할 것입니다. 고맙습니다. 미리 읽는 시간을내어주세요.
감사합니다.이 항목은 선택시 표시/숨기기 기능으로 잼에서 벗어날 수있었습니다. 작은 메모, 위의 코드에서 작은 맞춤법 오류가 있습니다. 다음과 같아야합니다 : $ .uniform.update ('select'); –