触发页面加载时选择选项加载的事件

时间:2017-10-25 19:21:37

标签: php jquery ajax

我想根据选定的行业类型获取业务类型列表。我正在使用以下代码 -

$('#industry_type').change(function () {
    var industry_id = $(this).val();
    getBusinessTypes(industry_id);
    return false;
});

function getBusinessTypes(industry_id) {
    $.ajax({
        url: baseURL + ('processes/org_process.php'),
        type: "POST",
        data: { 'action': 'all', 'industry_id': industry_id },
        success: function (data) {
            var business_type = $('#business_types');
            business_type.chosen('destroy');
            business_type.html(data);
            business_type.chosen({ width: "100%" });
        }
    });
}

这将返回业务类型列表。

这里的问题是,只有在更改选项时才会触发事件。如果在页面加载时已选择了选择选项,则它不会触发事件。

任何人都知道如何在页面加载时根据选定的行业类型获取业务类型列表?

谢谢!

1 个答案:

答案 0 :(得分:1)

绑定事件处理程序后添加.trigger('change')

$('#industry_type').change(function () {
    var industry_id = $(this).val();
    getBusinessTypes(industry_id);
    return false;
}).trigger('change');