繁体   English   中英

我怎样才能用js检查asp.net中“ DropDownList”的值?

[英]how i can check value of “DropDownList” in asp.net with js?

我是asp.net和Java脚本的新手。 我想用Java脚本检查asp:dropdownlist的值。

选择的值在数据库中定义,但是当我选择一个值为9的项目时,我没有得到“ hello” alert.any的身体可以帮助我吗? 谢谢。

<script>
    $(document).ready(function offermessage() {
        var a = ($('#<%=offermessage.ClientID %> option:selected').val());
        if(a==9)
        {
            alert("hello");
        }
    });
</script>

   <div class="col-12">
       <asp:DropDownList ID="offermessage" CssClass="farsi-font drp-down-list" required="" runat="server" >
           <asp:ListItem Value="Baseid">value</asp:ListItem>
       </asp:DropDownList>
   </div>

你可以尝试下面的代码吗

 $(document).ready(function(){
            function offermessage() {
            var a = $('#<%=offermessage.ClientID%>').val();
            if(a == 9)
            {
                alert("hello");
            }
          }
        });

如果要获取下拉列表的change事件的下拉列表的值,则可以添加以下代码

$(document).ready(function(){
  $('#<%=offermessage.ClientID%>').on('change',function(){
    var a = $(this).val();
      if(a == 9)
      {
       alert("hello");
      }
 });

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM