![](/img/trans.png)
[英]How to update a dropdown onchange of another dropdown and save it using AJAX and JavaScript
[英]Jquery onchange update another dropdown list
我用了兩個下拉列表
我希望當用戶在第一個列表中選擇2時,將執行以下腳本:
$('select[name="service"]').change(function(){
$('#modal-hs').show();
});
我試圖執行幾件事,例如:
$('select[name="service"]').on('change', function (e){...});
要么
$('select[name="service"]').trigger('change', function() { .. });
但這是行不通的。
修改$('select[name="reason"]').change
處理程序,如下所示:
// ...
if ($(this).val() == "2") {
$('#add-status').show();
$('select[name="service"]>option:eq(1)').prop('selected', true);
$('select[name="service"]').prop('disabled', true);
// Trigger the change event
$('select[name="service"]').trigger('change');
}
這是更新的JSFiddle: https ://jsfiddle.net/6gerwaf8/2/
之所以必須手動觸發change
事件,是因為change
事件需要由用戶啟動的實際瀏覽器事件。
你是這個意思嗎
if ($(this).val() == "2") {
$('#add-status').show();
$('select[name="service"]>option:eq(1)').prop('selected', true);
$('select[name="service"]').prop('disabled', true);
$('select[name="service"]').trigger("change");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.