下拉列表选择默认提交 [英] Dropdownlist selects to default on submit
本文介绍了下拉列表选择默认提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表,我绑定数据,点击提交按钮,下拉列表选择默认,有什么问题我的代码?
这是在validation.js文件中保存的jQuery验证:
Hi,
I have a dropdownlist , i'm binding the data, on click of a submit button the dropdownlist selects to default, what is the wrong with my code?
This is the jQuery validation kept in validation.js file:
$(document).ready(function () {
$('#btnsubmit').click(function () {
debugger;
var str = $('#ddl').val();
if (str == '--Select--') {
alert('Plz select Country');
return;
}
});
});
< br $>
我的设计页面是:
And my design page is :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Debugging.aspx.cs" Inherits="Debugging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="Scripts/jquery-2.0.2.js" type="text/javascript"></script>
<script src="Scripts/Validations.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="ddl" ></asp:DropDownList>
<asp:Button runat="server" ID="btnsubmit" Text="Submit"/>
</div>
</form>
</body>
</html>
推荐答案
(document).ready(function(){
(document).ready(function () {
(< span class =code-string>' #btnsubmit')。click(function(){
debugger;
var str =
('#btnsubmit').click(function () { debugger; var str =
(' #DDL'跨度>)VAL();
if (str == ' - 选择 - '){
alert(' Plz select Country') ;
return ;
}
});
});
('#ddl').val(); if (str == '--Select--') { alert('Plz select Country'); return; } }); });
和我的设计页面是:
And my design page is :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Debugging.aspx.cs" Inherits="Debugging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="Scripts/jquery-2.0.2.js" type="text/javascript"></script>
<script src="Scripts/Validations.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="ddl" ></asp:DropDownList>
<asp:Button runat="server" ID="btnsubmit" Text="Submit"/>
</div>
</form>
</body>
</html>
这篇关于下拉列表选择默认提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文