[英]Cascading Dropdown change on load of page
我有一個幾年前從互聯網上獲取的Jquery Cascading下拉列表,它運行良好。 但我想擴展它,以便在會議中記住團隊的選擇。
前提是團隊中有用戶,當您選擇一個團隊時,它將顯示該團隊中的活動用戶。 如果您在加載頁面后選擇了小組,但是如果設置了會話,則下拉列表不會級聯,並且您必須重新選擇小組以進行級聯,這將起作用。
$("select#memberid_active").attr("disabled", "disabled");
$("select#teamid_active").change(function() {
$("select#memberid_active").attr("disabled", "disabled");
$("select#memberid_active").html("<option>Wait...</option>");
var id = $("select#teamid_active option:selected").attr('value');
$.post("selectconsultant_active.php", {
id : id
}, function(data) {
$("select#memberid_active").removeAttr("disabled");
$("select#memberid_active").html(data);
});
});
這是下拉代碼,我可以使用PHP會話,但是在加載頁面時,級聯下拉列表不會更新。 該功能必須在頁面加載和更改時起作用。 我嘗試了幾種不同的方法,但實際上我對JQuery的了解還不足以使其正常工作。
任何幫助,將不勝感激。
謝謝
$("document").ready(function(){ /*This works to see if the active Option is valid by default when loaded from session and then fire the update method. As the default selected value for a dropdown is -1*/ if($("select#teamid_active").val() != -1){ //Fire the udpate if the team dropdown has a value on DOC ready updateTheUsersDropDown(); } }); $("select#memberid_active").attr("disabled", "disabled"); $("select#teamid_active").change(function() { updateTheUsersDropDown(); }); var updateTheUsersDropDown=function(){ $("select#memberid_active").attr("disabled", "disabled"); $("select#memberid_active").html("<option>Wait...</option>"); var id = $("select#teamid_active option:selected").attr('value'); $.post("selectconsultant_active.php", { id : id }, function(data) { $("select#memberid_active").removeAttr("disabled"); $("select#memberid_active").html(data); }); };
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
請嘗試一次
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.