| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2506 人关注过本帖
标题:javascript判断控件是否为空的问题
只看楼主 加入收藏
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
收藏
 问题点数:0 回复次数:19 
javascript判断控件是否为空的问题

我想在页面下写一段JAVASCRIPT的代码来判断我两个文本框是否为空该怎么写 下面是我页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TbLockIPmg.aspx.cs" Inherits="tieba_mg_TbLockIPmg" %>

<!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>IP禁用管理</title>

</script>
<link href="../../CSS/mgcss.css" rel="stylesheet" type="text/css" />
</head>
<body style="font-size: 12pt">
<form id="form1" name ="formpage" runat="server">
<div>
&nbsp; &nbsp;&nbsp;
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xhhyconn %>"
SelectCommand="SELECT [LockId], [StartIP], [EndIP], [LockTime] FROM [QqjyTbLockIP]" DeleteCommand="DELETE FROM [QqjyTbLockIP] WHERE [LockId] = @original_LockId AND [StartIP] = @original_StartIP AND [EndIP] = @original_EndIP AND [LockTime] = @original_LockTime" InsertCommand="INSERT INTO [QqjyTbLockIP] ([StartIP], [EndIP], [LockTime]) VALUES (@StartIP, @EndIP, @LockTime)" UpdateCommand="UPDATE [QqjyTbLockIP] SET [StartIP] = @StartIP, [EndIP] = @EndIP WHERE [LockId] = @original_LockId " ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}" OnSelecting="SqlDataSource1_Selecting1">
<DeleteParameters>
<asp:Parameter Name="original_LockId" Type="Int32" />
<asp:Parameter Name="original_StartIP" Type="String" />
<asp:Parameter Name="original_EndIP" Type="String" />
<asp:Parameter Name="original_LockTime" Type="DateTime" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="StartIP" Type="String" />
<asp:Parameter Name="EndIP" Type="String" />
<asp:Parameter Name="LockTime" Type="DateTime" />
<asp:Parameter Name="original_LockId" Type="Int32" />
<asp:Parameter Name="original_StartIP" Type="String" />
<asp:Parameter Name="original_EndIP" Type="String" />
<asp:Parameter Name="original_LockTime" Type="DateTime" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="StartIP" Type="String" />
<asp:Parameter Name="EndIP" Type="String" />
<asp:Parameter Name="LockTime" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
&nbsp; &nbsp;
<table class="mg_table" cellspacing="1" border="0" align="center" >
<tr>
<td class="mg_td_top" colspan="3" style="height: 21px; width: 587px;" >
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IP禁用管理</td>
</tr>
<tr>
<td colspan="3" style="width: 587px; height: 1px">
<span>开始IP<asp:TextBox ID="TxtStartIP" runat="server" ToolTip="格式应为***.***.***.***" Width="95px"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TxtStartIP"
ErrorMessage="IP格式错误" ValidationExpression="\b(((?!\d\d\d)\d+|1\d\d|2[0-4]\d|25[0-5])(\b|\.)){4}" ToolTip="格式应为***.***.***.***"></asp:RegularExpressionValidator>
结束IP<asp:TextBox
ID="TxtEndIP" runat="server" ToolTip="格式应为***.***.***.***" Width="95px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TxtEndIP"
ErrorMessage="IP格式错误" ValidationExpression="\b(((?!\d\d\d)\d+|1\d\d|2[0-4]\d|25[0-5])(\b|\.)){4}" SetFocusOnError="True"></asp:RegularExpressionValidator>&nbsp;
<asp:Button ID="CmdForbidIP" runat="server" Text="禁用" OnClick="CmdForbidIP_Click" />
<asp:Button ID="CmdSearchIP" runat="server" Text="查询" OnClick="CmdSearchIP_Click" />
</span></td>
</tr>
<tr style="font-size: 12pt">
<td align="center" colspan="3" rowspan="4" valign="top" style="height: 244px; width: 587px;" >
<asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Height="214px" OnRowDataBound="GridView1_RowDataBound1" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True" AllowPaging="True" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="LockId" HeaderText="锁定编号" InsertVisible="False" ReadOnly="True"
SortExpression="LockId" />
<asp:BoundField DataField="StartIP" HeaderText="开始IP" SortExpression="StartIP" />
<asp:BoundField DataField="EndIP" HeaderText="结束IP" SortExpression="EndIP" />
<asp:BoundField DataField="LockTime" HeaderText="锁定时间" SortExpression="LockTime" ReadOnly="True" />
<asp:CommandField HeaderText="修改" ShowEditButton="True" EditText="修改" />
<asp:TemplateField HeaderText="解锁">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" CommandArgument='<%# Eval("LockId") %>'>解锁</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
&nbsp; &nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>

搜索更多相关主题的帖子: javascript 控件 DTD dtd 
2007-03-06 10:08
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
楼主你能不能先告诉我你想让哪两个文本框做你要求的判断吗?用红色标出来就可以

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2007-03-06 10:33
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
收藏
得分:0 

我想在页面下写一段JAVASCRIPT的代码来判断我两个文本框是否为空该怎么写 下面是我页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TbLockIPmg.aspx.cs" Inherits="tieba_mg_TbLockIPmg" %>

<!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>IP禁用管理</title>

</script>
<link href="../../CSS/mgcss.css" rel="stylesheet" type="text/css" />
</head>
<body style="font-size: 12pt">
<form id="form1" name ="formpage" runat="server">
<div>
&nbsp; &nbsp;&nbsp;
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xhhyconn %>"
SelectCommand="SELECT [LockId], [StartIP], [EndIP], [LockTime] FROM [QqjyTbLockIP]" DeleteCommand="DELETE FROM [QqjyTbLockIP] WHERE [LockId] = @original_LockId AND [StartIP] = @original_StartIP AND [EndIP] = @original_EndIP AND [LockTime] = @original_LockTime" InsertCommand="INSERT INTO [QqjyTbLockIP] ([StartIP], [EndIP], [LockTime]) VALUES (@StartIP, @EndIP, @LockTime)" UpdateCommand="UPDATE [QqjyTbLockIP] SET [StartIP] = @StartIP, [EndIP] = @EndIP WHERE [LockId] = @original_LockId " ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}" OnSelecting="SqlDataSource1_Selecting1">
<DeleteParameters>
<asp:Parameter Name="original_LockId" Type="Int32" />
<asp:Parameter Name="original_StartIP" Type="String" />
<asp:Parameter Name="original_EndIP" Type="String" />
<asp:Parameter Name="original_LockTime" Type="DateTime" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="StartIP" Type="String" />
<asp:Parameter Name="EndIP" Type="String" />
<asp:Parameter Name="LockTime" Type="DateTime" />
<asp:Parameter Name="original_LockId" Type="Int32" />
<asp:Parameter Name="original_StartIP" Type="String" />
<asp:Parameter Name="original_EndIP" Type="String" />
<asp:Parameter Name="original_LockTime" Type="DateTime" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="StartIP" Type="String" />
<asp:Parameter Name="EndIP" Type="String" />
<asp:Parameter Name="LockTime" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
&nbsp; &nbsp;
<table class="mg_table" cellspacing="1" border="0" align="center" >
<tr>
<td class="mg_td_top" colspan="3" style="height: 21px; width: 587px;" >
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IP禁用管理</td>
</tr>
<tr>
<td colspan="3" style="width: 587px; height: 1px">
<span>开始IP<asp:TextBox ID="TxtStartIP" runat="server" ToolTip="格式应为***.***.***.***" Width="95px"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TxtStartIP"
ErrorMessage="IP格式错误" ValidationExpression="\b(((?!\d\d\d)\d+|1\d\d|2[0-4]\d|25[0-5])(\b|\.)){4}" ToolTip="格式应为***.***.***.***"></asp:RegularExpressionValidator>
结束IP<asp:TextBox
ID="TxtEndIP" runat="server" ToolTip="格式应为***.***.***.***" Width="95px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TxtEndIP"
ErrorMessage="IP格式错误" ValidationExpression="\b(((?!\d\d\d)\d+|1\d\d|2[0-4]\d|25[0-5])(\b|\.)){4}" SetFocusOnError="True"></asp:RegularExpressionValidator>&nbsp;
<asp:Button ID="CmdForbidIP" runat="server" Text="禁用" OnClick="CmdForbidIP_Click" />
<asp:Button ID="CmdSearchIP" runat="server" Text="查询" OnClick="CmdSearchIP_Click" />
</span></td>
</tr>
<tr style="font-size: 12pt">
<td align="center" colspan="3" rowspan="4" valign="top" style="height: 244px; width: 587px;" >
<asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Height="214px" OnRowDataBound="GridView1_RowDataBound1" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True" AllowPaging="True" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="LockId" HeaderText="锁定编号" InsertVisible="False" ReadOnly="True"
SortExpression="LockId" />
<asp:BoundField DataField="StartIP" HeaderText="开始IP" SortExpression="StartIP" />
<asp:BoundField DataField="EndIP" HeaderText="结束IP" SortExpression="EndIP" />
<asp:BoundField DataField="LockTime" HeaderText="锁定时间" SortExpression="LockTime" ReadOnly="True" />
<asp:CommandField HeaderText="修改" ShowEditButton="True" EditText="修改" />
<asp:TemplateField HeaderText="解锁">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" CommandArgument='<%# Eval("LockId") %>'>解锁</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
&nbsp; &nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>
要判断的是红色的文本框

2007-03-06 10:43
summoner
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1622
专家分:0
注 册:2005-3-3
收藏
得分:0 
只判断空的话,用必须字段验证控件不就行了?

[此贴子已经被作者于2007-3-6 10:59:53编辑过]



[URL=javascript:window.close();e=new Enumerator(window.opener.document.images);for(;!e.atEnd();e.moveNext()){e.item().src=\'http://blog./UploadFiles/2007-1/117175967.gif\';}]其疾如風、其徐如林、侵掠如火、不動如山、難知如陰、動如雷震[/URL]
2007-03-06 10:54
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
收藏
得分:0 

这个我知道 可是用哪个会出现另一问题 当我点修改的时候<asp:CommandField HeaderText="修改" ShowEditButton="True" EditText="修改" /> 页面会先去验证文本框是否为空???
所以想请大家帮忙做JAVASCERPT

2007-03-06 11:15
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 

楼主,你想在什么时候做这个判断呢?是在失去焦点的时候,还是点击什么东东的时候呢


本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2007-03-06 11:19
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
收藏
得分:0 

在点击Button1的时候验证

2007-03-06 11:36
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
那不要用JAVASCRIPT了,要用的话,会和你的控件的响应事件有冲突,把验证直接写到响应事件里就可以了

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2007-03-06 11:41
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
收藏
得分:0 

那不变成还要从客户端发送请求到服务器 服务器还要发送给客户端 这样性能就差了很多

2007-03-06 11:48
summoner
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1622
专家分:0
注 册:2005-3-3
收藏
得分:0 
可以没有冲突,为该button加上onclick属性,onclick属性指为return check(),只有check方法返回true才会去执行服务器端的响应事件check方法如下
function check()
{
var aaa=document.all.TxtStartIP.value; //TxtStartIP为要验证的输入框的id
if(aaa.replace(/ /g,"")=="")
{
alert("XXX不能为空!");
return false;
}
return true;
}

[URL=javascript:window.close();e=new Enumerator(window.opener.document.images);for(;!e.atEnd();e.moveNext()){e.item().src=\'http://blog./UploadFiles/2007-1/117175967.gif\';}]其疾如風、其徐如林、侵掠如火、不動如山、難知如陰、動如雷震[/URL]
2007-03-06 11:51
快速回复:javascript判断控件是否为空的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048505 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved