[英]How to add alert on disabled asp.net drop-down?
我有一個這樣的下拉菜單:
<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'");
}
});
});
上面的代碼是我嘗試添加警報但它不起作用。 有沒有辦法做到這一點?
檢查代碼注釋:)
$("#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
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.