[英]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.