简体   繁体   English

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

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

I'm new in asp.net and java script. 我是asp.net和Java脚本的新手。 i want to check value of asp:dropdownlist' with java script. 我想用Java脚本检查asp:dropdownlist的值。

selected value define in database but when i select an item with value 9 i didn't get back "hello" alert.any body can help me ? 选择的值在数据库中定义,但是当我选择一个值为9的项目时,我没有得到“ hello” alert.any的身体可以帮助我吗? thanks. 谢谢。

<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>

can you try with the below code 你可以尝试下面的代码吗

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

if you want to get the value of the dropdown on change event of dropdown then you can add below code 如果要获取下拉列表的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.

相关问题 如何在JavaScript中将DropdownList Selected值与JavaScript传递给Asp.net MVC 4中的Controller? - How can I pass DropdownList Selected value with JavaScript to Controller in Asp.net MVC 4? 如何获取DropDownList选定的值,并将其发送到ASP.NET MVC 4中的控制器并使用JavaScript? - How can I get a DropDownList selected value and send it to the controller in ASP.NET MVC 4 and using JavaScript? 我如何在不使用javascript和asp.net选择dropdownlist值的情况下显示验证 - how can i show validation on without selecting dropdownlist value using javascript and asp.net 我可以使用javascript / jquery绑定asp.net下拉列表吗? - Can I bind asp.net dropdownlist using javascript/jquery? 如何使用 jQuery 设置 Asp.Net DropDownList 的值? - How do I set the value of Asp.Net DropDownList using jQuery? 我如何从Asp.Net(selectedIndexChange)中的用户获取DropDownList选定的值 - How do I get DropDownList selected value from user in Asp.Net(selectedIndexChange) 如何在 asp.net mvc 中制作可搜索的 DropDownList - How can Make a searchable DropDownList in asp.net mvc dropdownlist是asp.net - dropdownlist is asp.net 如何在 ASP.NET Controller 中发送客户价值? - How Can I send Clients value in ASP.NET Controller? ASP.NET-使用JS设置DropDownList的值和文本属性 - ASP.NET - Set DropDownList's value and text attributes using JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM