Javascript 如何在禁用的asp.net下拉列表中添加警报?
我有这样一个下拉列表:Javascript 如何在禁用的asp.net下拉列表中添加警报?,javascript,jquery,asp.net,json,Javascript,Jquery,Asp.net,Json,我有这样一个下拉列表: <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
<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>
上面的代码是我尝试添加警报的代码,但它不起作用。
有什么方法可以做到这一点吗?检查代码上的注释:)
是的,有一种方法,叫做jQuery。禁用的元素不能引发事件。可能会有帮助
$(document).ready(function() {
$("#cboJPRem").change(function(){
if($("#cboJPRem:selected").attr("id") == "cboXyz"){
alert("To enable this drop down, change the value of 'check A'");
}
});
});
$("#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
}
});