3

嘿,我正在尝试在 jquery 中获取我的下拉列表的值或选定索引。当我尝试这个时,它会以未定义的形式返回。当我尝试 .index() 它只给我索引而不是选定的索引。

<td>
    <asp:DropDownList id="ddlFullName" runat="server" Width="48px" />
</td>

这是我的 Jquery。

$(document).ready(function () {

        $("select[id$='_ddlFullName']").change(function () {

            console.log("changed");
            var selectedText = $("select[id$='_dllFullName'] option:selected").val();
            console.log("selected text= " + selectedText);              
        });

    });

另一件事。我正在使用 DotNetNuke,因此在客户端它将我的下拉列表包装到一个链接中,其中所选值或文本显示在一个跨度中,如下所示。

<a href="javascript:void(0)" id="Skinneddnn_ctr481_ViewResellerSite_Dashboard_ResellerSite/BulkMailingProcessingMain_ddlFullName" unselectable="on" tabindex="-1" class="rfdSelect rfdSelect_Growll" style="width: 44px;"><span class="rfdSelectOuter"><span class="rfdSelectText">c_county</span></span></a>

下面的实际下拉列表

<select name="dnn$ctr481$ViewResellerSite$Dashboard$ResellerSite/BulkMailingProcessingMain$ddlFullName" id="dnn_ctr481_ViewResellerSite_Dashboard_ResellerSite/BulkMailingProcessingMain_ddlFullName" style="width: 44px;" class="rfdRealInput" _rfddecoratedid="Skinneddnn_ctr481_ViewResellerSite_Dashboard_ResellerSite/BulkMailingProcessingMain_ddlFullName">
                <option value=""></option>
                <option value="c_add1">c_add1</option>
                <option value="c_city">c_city</option>
                <option value="c_state">c_state</option>
                <option value="c_zip">c_zip</option>
                <option value="c_key">c_key</option>
                <option value="c_f_nm">c_f_nm</option>
                <option value="c_l_nm">c_l_nm</option>
                <option value="c_add2">c_add2</option>
                <option value="c_county">c_county</option>
                <option value="c_country">c_country</option>
                <option value="c_phone">c_phone</option>
                <option value="c_company">c_company</option>
                <option value="c_fax">c_fax</option>
                <option value="c_pager">c_pager</option>
                <option value="c_cellular">c_cellular</option>
                <option value="c_em">c_em</option>
                <option value="pw">pw</option>
                <option value="username">username</option>
                <option value="gender">gender</option>
                <option value="opt1">opt1</option>
                <option value="s_f_nm">s_f_nm</option>
                <option value="s_l_nm">s_l_nm</option>
                <option value="s_add1">s_add1</option>
                <option value="s_add2">s_add2</option>
                <option value="s_city">s_city</option>
                <option value="s_state">s_state</option>
                <option value="s_county">s_county</option>
                <option value="s_zip">s_zip</option>
                <option value="s_country">s_country</option>
                <option value="s_phone">s_phone</option>
                <option value="s_fax">s_fax</option>
                <option value="s_company">s_company</option>
                <option value="s_pager">s_pager</option>
                <option value="s_cellular">s_cellular</option>
                <option value="cg_id">cg_id</option>
                <option value="opt3">opt3</option>
                <option value="opt2">opt2</option>
                <option value="ibo">ibo</option>
                <option value="sibo">sibo</option>
                <option value="libo">libo</option>
                <option value="plevel">plevel</option>
                <option value="var_num">var_num</option>
                <option value="var_name">var_name</option>
                <option value="var_type">var_type</option>
                <option value="var_ref">var_ref</option>
                <option value="pay_method">pay_method</option>
                <option value="sales_exempt">sales_exempt</option>
                <option value="sacct_code">sacct_code</option>
                <option value="cctype">cctype</option>
                <option value="logon_redirect">logon_redirect</option>
                <option value="logon_redirect_pagename">logon_redirect_pagename</option>
                <option value="mgr_account_access">mgr_account_access</option>
                <option value="mgr_managerfront_access">mgr_managerfront_access</option>
                <option value="type">type</option>
                <option value="s_flospath">s_flospath</option>
                <option value="flospath">flospath</option>
                <option value="blospath">blospath</option>
                <option value="s_blospath">s_blospath</option>
                <option value="bsponsor">bsponsor</option>
                <option value="fsponsor">fsponsor</option>
                <option value="flospath_level">flospath_level</option>
                <option value="blospath_level">blospath_level</option>
                <option value="spouse_f_nm">spouse_f_nm</option>
                <option value="spouse_l_nm">spouse_l_nm</option>
                <option value="bus_type">bus_type</option>
                <option value="emdate">emdate</option>
                <option value="leglock">leglock</option>
                <option value="leg_strength">leg_strength</option>
                <option value="bleg">bleg</option>
                <option value="bactivated">bactivated</option>
                <option value="blmvol">blmvol</option>
                <option value="bqualfied">bqualfied</option>
                <option value="flag1">flag1</option>
                <option value="flag2">flag2</option>
                <option value="flag4">flag4</option>
                <option value="flag5">flag5</option>
                <option value="flag3">flag3</option>
                <option value="NotifyFlag">NotifyFlag</option>
                <option value="CustomerPath">CustomerPath</option>
                <option value="CustFlags1">CustFlags1</option>
                <option value="cust_ser_logon">cust_ser_logon</option>
                <option value="opt4">opt4</option>
                <option value="opt5">opt5</option>
                <option value="opt6">opt6</option>
                <option value="opt7">opt7</option>
                <option value="opt8">opt8</option>
                <option value="opt9">opt9</option>
                <option value="opt10">opt10</option>
                <option value="opt11">opt11</option>
                <option value="opt12">opt12</option>
                <option value="opt13">opt13</option>
                <option value="opt14">opt14</option>
                <option value="opt15">opt15</option>
                <option value="features">features</option>
                <option value="bleg1">bleg1</option>
                <option value="row_added">row_added</option>
                <option value="status">status</option>
                <option value="ws_nm">ws_nm</option>
                <option value="date">date</option>

            </select>
4

3 回答 3

1

演示--> http://jsfiddle.net/3AFwj/

当您申请课程时,请使用Class选择器而不是ID

 $(".rfdRealInput").change(function () {
       console.log("changed");
       var selectedText = $(".rfdRealInput option:selected").val();
       console.log("selected text= " + selectedText);              
  });
于 2013-06-21T13:00:21.120 回答
1

尝试这个,

$(function(){
     $("select#ddlFullName").change(function () {
            console.log("changed");
            var selectedText = $(this).val();
            console.log("selected text= " + selectedText);              
     });
});
于 2013-06-21T12:58:53.870 回答
0
Try using selector like this:

 $(document).ready(function () {

    $("#ddlFullName").change(function () {

        console.log("changed");
        var selectedText = $("#dllFullName").val();
        console.log("selected text= " + selectedText);              
    });

});
于 2013-06-21T13:00:46.617 回答