동적으로 의존하는 4 개의 선택 메뉴가 있습니다. 메뉴는 주, 카운티, 지역, 이웃에 해당합니다. 동적 종속성은 jQuery 스크립트를 통해 달성됩니다. 내가 성취하고자하는 것은 각 메뉴에 대해 사용자가 선택한 마지막 옵션을 메뉴에 기억시키는 것입니다. 그래서 트릭을 수행 할 URL 매개 변수를 가져올 수 있다고 생각했습니다. 그래서 나는jquery로 선택 메뉴 옵션 기억하기
getCounty: function (results) {
if(!results) return;
var allCounties = $("<option value=\"All\">All Counties </option>");
counties.html(results);
counties.prepend(allCounties);
var w = $.query.get("county_id");
if(w) {
counties.val(w).attr('selected', true);
} else {
counties.val("All").attr('selected', true);
}
가 $.query.get
기능 정확 .... 이런 식으로 스크립트를 수정? 내 코드에 문제가 있습니까? 나는 내가 jQuery를 전문가가 아니라고 인정해야 ... 코드는 내가
counties.val(3).attr('selected',true)
선택 메뉴의 세 번째 옵션이 선택됩니다를 입력하면 잘 작동합니다.
내가,var county = getUrlVars()["county_id"];
if (county)
counties.val(county).attr('selected',true);
else
counties.val("All").attr('selected',true);
왜'attr ('selected', true)'를 사용합니까? – zerkms