JS给HTML5页面<Select></Select>绑定选中项

桓修能
2023-12-01

获取选中值:

function setApprovalPersonName() {
            var name = $("#approvalPersion").find("option:selected").text();
            document.getElementById("approvalPersonName").value = name;
        }

刷新列表:

$("#is_conference").children()[1].selected = true;
    $("#is_conference").selectpicker('refresh');

例1:

 1 //第二级案件类型发生改变
 2         $("#SecondCasetypelist").change(function () {
 3             var child = $("#SecondCasetypelist").children();
 4             var selecting = 0;
 5             for (i = 0; i < child.length; i++) {
 6                 if (child[i].selected) {
 7                     selecting += 1;
 8                 }
 9             }
10             if(selecting == 0)
11             {
12                 child[0].selected = true;
13             }
14             else if(selecting > 1)
15             {
16                 child[0].selected = false;
17             }
18             loadHtml($('#tableCustom'), 'CustomReport', { Year: $("#Year").val(), Month: $("#Month").val(), caseStatus: $("#SecondCasetypelist").val(),flot:"2" });
19         });

例2:

 1  //列出会议类型函数
 2     function appendStrConferenceType(source)
 3     {
 4         debugger
 5         var type = $('#con_category').children();
 6         if(source == 1)
 7         {
 8             type[0].selected = true;
 9         }
10         else if(source == 2)
11         {
12             type[1].selected = true;
13         }
14         else 
15         {
16             type[2].selected = true;
17         }
18     }

 

转载于:https://www.cnblogs.com/lijianda/p/6964235.html

 类似资料: