【问题标题】:How to add alert on disabled asp.net drop-down?如何在禁用的 asp.net 下拉列表中添加警报?
【发布时间】:2020-03-21 17:49:06
【问题描述】:

我有一个这样的下拉菜单:

<asp:DropDownList ID="cboJPRem" class="jprem" runat="server">
     <asp:ListItem Value="None" Selected="True" Text="None"></asp:ListItem>
     <asp:ListItem Value="1day" Text="1 day"></asp:ListItem> 
</asp:DropDownList>

根据字段“检查 A”的值禁用和启用此下拉菜单。如果检查 A 是 'T',下拉将被启用,如果检查 A 是 'F' 下拉将被禁用。

我的要求是在用户单击禁用的下拉菜单时发出警报消息(要启用此下拉菜单,请更改“检查 A”的值)。

$(document).ready(function() {
            $("#cboJPRem").change(function(){
                if($("#cboJPRem:selected").attr("id") == "cboXyz"){
                    alert("To enable this drop down, change the value of 'check A'");
                }
            });

        });

上面的代码是我尝试添加警报但它不起作用。 有没有办法做到这一点?

【问题讨论】:

标签: javascript jquery asp.net json


【解决方案1】:

在代码上检查 cmets:)

$("#cboJPRem").on('change', function() {

    //this will help you to retrive the selected value. 
    var yourVal = $('option:selected', this).attr("id"); 

    //confirm if value is retrived properly
    console.log(yourVal);

    if(yourVal == "cboXyz") {
        //do your stuff
    }
});

【讨论】:

    猜你喜欢
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多