我写了一个登陆页面,用JS判断两个文本框是否为空,点“登陆”图片按钮为什么还一闪一闪的,感觉应该是提交到服务器端了,请问这是什么原因?
我执行的是客户端脚本,应该不会这样才对呀?
Aspx 脚本如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="登陆.aspx.cs" Inherits="登陆" %>
<!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 runat="server">
<title>登陆</title>
</head>
<body>
<script src="js/myJScript.js" ></script> <form id="form1" runat="server">
<div>
<br />
</div>
<table align="center" cellpadding="0" cellspacing="0" style="border-right: #ff3366 thin solid;
border-top: #ff3366 thin solid; border-left: #ff3366 thin solid; width: 581px;
border-bottom: #ff3366 thin solid">
<tr>
<td style="width: 34px; height: 22px; text-align: right">
<strong><em>Name:</em></strong></td>
<td style="width: 217px; height: 22px">
<asp:TextBox ID="txt_Name" runat="server" Height="26px" Style="position: relative"
Width="228px"></asp:TextBox></td>
<td rowspan="3" style="width: 41px">
<asp:ImageButton ID="ImageButton1" runat="server" Height="137px" ImageUrl="~/image/TV.jpg"
Style="position: static" Width="259px" /></td>
</tr>
<tr>
<td style="width: 34px; height: 22px; text-align: right">
<strong><em>Pwd:</em></strong></td>
<td style="width: 217px; height: 22px">
<asp:TextBox ID="txt_Pwd" runat="server" Height="26px" Style="position: relative;
top: 1px" TextMode="Password" Width="228px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 34px; border-right-style: dashed; height: 67px; border-right-color: #6699ff">
</td>
<td style="width: 217px; height: 67px">
<asp:ImageButton ID="btn_ok" runat="server" Height="34px" ImageUrl="~/image/login.GIF"
Style="left: 0px; position: relative; top: 0px" Width="102px" OnClientClick="check()" />
<asp:ImageButton ID="btn_exit" runat="server" Height="34px" ImageUrl="~/image/cancel.gif"
Style="left: 0px; position: relative; top: 0px" Width="102px" OnClick="btn_exit_Click" />
</td>
</tr>
</table>
</form>
</body>
</html>
**********************\\ myJScript.js \\**************************
function check()
{
var txt1 = document.getElementById("txt_Name");
var txt2 = document.getElementById("txt_Pwd");
//alert("请输入用户名!");
if (txt1 && txt1.value=='')
{
alert("请输入用户名!",64,"系统提示");
txt1.focus();
return false;
}
if (txt2 && txt2.value=='')
{
alert("密码不能为空!");
txt2.focus();
return false;
}
return true;
}
我执行的是客户端脚本,应该不会这样才对呀?
Aspx 脚本如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="登陆.aspx.cs" Inherits="登陆" %>
<!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 runat="server">
<title>登陆</title>
</head>
<body>
<script src="js/myJScript.js" ></script> <form id="form1" runat="server">
<div>
<br />
</div>
<table align="center" cellpadding="0" cellspacing="0" style="border-right: #ff3366 thin solid;
border-top: #ff3366 thin solid; border-left: #ff3366 thin solid; width: 581px;
border-bottom: #ff3366 thin solid">
<tr>
<td style="width: 34px; height: 22px; text-align: right">
<strong><em>Name:</em></strong></td>
<td style="width: 217px; height: 22px">
<asp:TextBox ID="txt_Name" runat="server" Height="26px" Style="position: relative"
Width="228px"></asp:TextBox></td>
<td rowspan="3" style="width: 41px">
<asp:ImageButton ID="ImageButton1" runat="server" Height="137px" ImageUrl="~/image/TV.jpg"
Style="position: static" Width="259px" /></td>
</tr>
<tr>
<td style="width: 34px; height: 22px; text-align: right">
<strong><em>Pwd:</em></strong></td>
<td style="width: 217px; height: 22px">
<asp:TextBox ID="txt_Pwd" runat="server" Height="26px" Style="position: relative;
top: 1px" TextMode="Password" Width="228px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 34px; border-right-style: dashed; height: 67px; border-right-color: #6699ff">
</td>
<td style="width: 217px; height: 67px">
<asp:ImageButton ID="btn_ok" runat="server" Height="34px" ImageUrl="~/image/login.GIF"
Style="left: 0px; position: relative; top: 0px" Width="102px" OnClientClick="check()" />
<asp:ImageButton ID="btn_exit" runat="server" Height="34px" ImageUrl="~/image/cancel.gif"
Style="left: 0px; position: relative; top: 0px" Width="102px" OnClick="btn_exit_Click" />
</td>
</tr>
</table>
</form>
</body>
</html>
**********************\\ myJScript.js \\**************************
function check()
{
var txt1 = document.getElementById("txt_Name");
var txt2 = document.getElementById("txt_Pwd");
//alert("请输入用户名!");
if (txt1 && txt1.value=='')
{
alert("请输入用户名!",64,"系统提示");
txt1.focus();
return false;
}
if (txt2 && txt2.value=='')
{
alert("密码不能为空!");
txt2.focus();
return false;
}
return true;
}
解决方案 »
- aspx vs ajax
- 网上商城,产品的折扣设置
- 如何实现关于ImageMap的RectangleHotSpot的特效问题
- asp.net 读取 sqlserver 表结构
- 高手请进:由嵌套form引起提交按钮失效的问题??????
- 在线急等,那里能下载动网新闻系统。
- 怎样在最新的新闻条目后面加上new的图标
- 求正则表达式,要求>0<32000
- 在自定义控件上DataGrid编辑功能不起作用?直接在ASP.NET页面上演示例子正常.
- 看我这条语句response.write("<script>open('page1.aspx?v_id=****','',400,300)</script>") 带***的地方我想用一服务器端变量代替,能
- 正则表达式高手请进
- 初次接触URL重写...紧急求助...
我是用的这个事件呀:onclientclick
另非要用“客户端控件 ”?
Style="left: 0px; position: relative; top: 0px" Width="102px" OnClientClick="check()" />
你使用HTML标签试试
你改下:OnClientClick = "return check()"