如何在不使用javascript和asp.net选择dropdownlist值的情况下显示验证
how can i show validation on without selecting dropdownlist value using javascript and asp.net
我有dropdownlist和一个文件上传按钮,因为当我没有选择dropdownlistvalue时,我想显示错误消息我只使用java脚本来引发错误消息我试过的代码是:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" lang="javascript">
$(document).ready(function () {
$('#txtBoxValue').click(function () {
if ($("#ddlsubjname").val() > 0) {
return true;
}
else {
alert('Please select Country')
return false;
}
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center"><tr><td>
<asp:DropDownList ID="ddlsubjname" runat="server" >
<asp:ListItem>--Select Items--</asp:ListItem>
<asp:listitem>Apple</asp:listitem>
<asp:listitem>>Mango</asp:listitem>
<asp:listitem>Grapes</asp:listitem>
</asp:DropDownList>
</td></tr>
<tr><td></td></tr>
<tr>
<td>
<span id="txtBoxValue"><asp:FileUpload ID="filuploadmp3" runat="server" /></span>
</td>
<td><asp:Label ID="lblmsg" runat="server" Text=""></asp:Label></td>
</tr>
</table>
有人能帮我解决吗
我对你的问题了解多少。。。您可以使用此示例验证您的下拉列表
<asp:DropDownList ID="ddlFruits" runat="server">
<asp:ListItem Text="Please Select" Value=""></asp:ListItem>
<asp:ListItem Text="Mango" Value="1"></asp:ListItem>
<asp:ListItem Text="Apple" Value="2"></asp:ListItem>
<asp:ListItem Text="Orange" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnSubmit" Text="Validate" runat="server" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSubmit]").click(function () {
var ddlFruits = $("[id*=ddlFruits]");
if (ddlFruits.val() == "") {
//If the "Please Select" option is selected display error.
alert("Please select an option!");
return false;
}
return true;
});
});
</script>
相关文章:
- 下拉选择可自动更改第二个下拉选择
- 如何使用jQuery选择下拉列表的值
- jquery点击函数select&取消选择
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 按照选项卡索引的顺序循环一个jQuery选择
- 在动态创建的元素上获取对特定选择器的引用
- AngularJS-在JSON选择器中使用变量名
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 获取选择框的状态
- 引导选择DropDownList不显示
- 如何在不使用javascript和asp.net选择dropdownlist值的情况下显示验证
- 正在将Jquery UI日期选择器链接到DropDownlist
- 选择Dropdownlist选项时在文本框上显示值
- 使用jQuery的DropDownList依赖项和选择
- 在dropdownlist中选择一个不带id的值
- 基于对另一个ASP:dropdownlist.value的选择禁用ASP:dropdownlist
- 实现JQuery函数以在每次选择DropDownList时触发事件
- 使用Jquery更改asp:DropDownList的默认选择值
- MVC DropDownList选择已更改,未启动Ajax
- 使用jQuery或Javascript在选择DropDownList值时填充多个文本框