在下拉列表中加载默认值并调用 onchange 事件

Loading default value in a dropdown and calling onchange event

本文关键字:调用 onchange 事件 默认值 下拉列表 加载      更新时间:2023-09-26

嗨,我有以下下拉菜单

<div class="fcolumn">
    <label class="text" for="o_Id">Months:</label>
    <select class="textMonths" id="o_Id" name="periodName" >
        <option value="000">Select Period--</option>
    </select>
</div> 

在下面的jquery中,首先在下拉列表中加载fnLoadP()。比作为默认值,我正在加载下拉列表中的值之一,即"10"。它也作为默认值加载。但它应该执行 $("#o_Id").change.. 它没有。

$(document).ready(function () {
    var sProfileUserId = null;
    $("#o_Id").change(function () {
        //----
    });
    fnLoadP();
    $("select[name='pName']").val('10');      
});
});

基本上我的目标是。加载下拉值后,加载"10"作为默认值并在 dom 中调用 onchange 事件。请让我知道如何解决它。

请将以下行添加到 fnLoadP();

$("select[name='pName']").val('10');      

我可以在这方面为您提供更多帮助,如果您共享 fnLoadP(); 代码。