0

私はaspドロップダウンリストを持っています:

<asp:DropDownList runat="server" ID="select_install_type" name="select install type">
                          <asp:ListItem Values="0" id ="installTypeMeterAndTransmitter" />   
                           <asp:ListItem Values="1" id ="installTypeTransmitterOnly" /> 
                            <asp:ListItem Values="2" id="installTypeMeterOnly"/>
                         </asp:DropDownList>

ローカライズされた名前でサーバー側に入力するアイテム:

private void FillInstallTypeControl()
        {
            this.select_install_type.Items[0].Text = CultureResourceHelper.GetConst("meter_and_transmitter");
            this.select_install_type.Items[1].Text = CultureResourceHelper.GetConst("transmitter_only");
            this.select_install_type.Items[2].Text = CultureResourceHelper.GetConst("meter_only");
        }

ここで、選択が変更されたときに実行する単純なjqueryメソッドを作成し、新しい選択に従って次のことを実行します。

            $('#select_install_type').change(function () {

                select_install_type.
                var selected = ($("#select_install_type").val());
              }

選択した値を取得できますが、ローカライズされているため、そのテキストを次のような文字列と比較したくありません。

if (selected == "אאאא")
{ //Do something
}

どのアイテムが選択されたかをどのように知ることができますか?多分選択されたインデックスまたはIDを取得しますか?しかし、私はjqueryを初めて使用するので、その方法がわかりません。

よろしくお願いします。

4

1 に答える 1

3

試す:

  $('#' + <%= select_install_type.ClientID %>).change(function () {
            var selected = $(this).val();
  }

または、選択したオプションのIDを取得できます。

  $('#' + <%= select_install_type.ClientID %>).change(function () {
            var selected = $(this).find('option:selected').prop("id");
  }

jQuery Sample

于 2013-03-07T13:26:31.097 に答える