Code
function CheckForm()
{
var i=0;
var txtTilles=document.getElementById("txtTitle"+i);
do
{
if(txtTilles.value=="")
{
errMessageLable("请输入标题");
return false;
}
txtTilles=document.getElementById("txtTitle"+(++i));
}
while(txtTilles)
return true;
}
function CheckForm()
{
var i=0;
var txtTilles=document.getElementById("txtTitle"+i);
do
{
if(txtTilles.value=="")
{
errMessageLable("请输入标题");
return false;
}
txtTilles=document.getElementById("txtTitle"+(++i));
}
while(txtTilles)
return true;
}
JS 错误信息提示
Code
function errMessageLable(strMessage)
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.style.color="red";
lblErrMes.innerText=strMessage;
}
function ClearErrMessageLable()
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.innerText="";
}
function errMessageLable(strMessage)
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.style.color="red";
lblErrMes.innerText=strMessage;
}
function ClearErrMessageLable()
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.innerText="";
}
aspx页面 里 为BUTTON 添加 OnClientClick事件:
Code
<asp:Button ID="btnUPload" runat="server" Text="上传" OnClientClick="if( !CheckForm()){setTimeout(ClearErrMessageLable ,6000);return false}" onclick="btnUPload_Click" />
完整代码如下
<asp:Button ID="btnUPload" runat="server" Text="上传" OnClientClick="if( !CheckForm()){setTimeout(ClearErrMessageLable ,6000);return false}" onclick="btnUPload_Click" />
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>
<!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>
<style type="text/css">
.style1
{
293px;
}
.style2
{
94px;
}
.style3
{
153px;
}
</style>
<script language="javascript" type="text/javascript">
// <!CDATA[
function btnAddOther_onclick()
{
var divVideo=document.getElementById("videoFileUPControl");
var newinput=document.createElement("input");
newinput.type="file";
divVideo.appendChild(newinput);
}
function CheckForm()
{
var i=0;
var txtTilles=document.getElementById("txtTitle"+i);
do
{
if(txtTilles.value=="")
{
errMessageLable("请输入标题");
return false;
}
txtTilles=document.getElementById("txtTitle"+(++i));
}
while(txtTilles)
}
function errMessageLable(strMessage)
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.style.color="red";
lblErrMes.innerText=strMessage;
}
function ClearErrMessageLable(strMessage)
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.innerText="";
}
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<div>
<table style="100%;">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="上传视频"></asp:Label>
</td>
<td class="style3">
标题:</td>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="文件:"></asp:Label>
</td>
<td>
<asp:Label ID="lblErrMes" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td class="style2" valign="top">
</td>
<td class="style3">
<asp:Panel ID="titlePanl" runat="server" >
<asp:TextBox ID="txtTitle0" runat="server"></asp:TextBox>
</asp:Panel>
</td>
<td class="style1">
<asp:Panel ID="videoFileUPControl" runat="server" >
<asp:FileUpload ID="FileUpload1" runat="server" />
</asp:Panel>
</td>
<td valign="top">
<!--
<input ID="btnAddOther" type="button" value="添加视频" onclick="return btnAddOther_onclick()" />
-->
<asp:Button ID="btnAddOther" runat="server" Text="添加视频"
onclick="btnAddOther_Click" />
<asp:Button ID="btnSub" runat="server" onclick="btnSub_Click" Text="减少" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
<asp:Button ID="btnUPload" runat="server" Text="上传" OnClientClick="if( !CheckForm()){setTimeout(ClearErrMessageLable ,6000);return false}" onclick="btnUPload_Click" />
</td>
<td class="style1">
<asp:Button ID="Button1" runat="server" Text="重置"
onclick="Button1_Click" />
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>
<!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>
<style type="text/css">
.style1
{
293px;
}
.style2
{
94px;
}
.style3
{
153px;
}
</style>
<script language="javascript" type="text/javascript">
// <!CDATA[
function btnAddOther_onclick()
{
var divVideo=document.getElementById("videoFileUPControl");
var newinput=document.createElement("input");
newinput.type="file";
divVideo.appendChild(newinput);
}
function CheckForm()
{
var i=0;
var txtTilles=document.getElementById("txtTitle"+i);
do
{
if(txtTilles.value=="")
{
errMessageLable("请输入标题");
return false;
}
txtTilles=document.getElementById("txtTitle"+(++i));
}
while(txtTilles)
}
function errMessageLable(strMessage)
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.style.color="red";
lblErrMes.innerText=strMessage;
}
function ClearErrMessageLable(strMessage)
{
var lblErrMes=document.getElementById("lblErrMes");
lblErrMes.innerText="";
}
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<div>
<table style="100%;">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="上传视频"></asp:Label>
</td>
<td class="style3">
标题:</td>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="文件:"></asp:Label>
</td>
<td>
<asp:Label ID="lblErrMes" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td class="style2" valign="top">
</td>
<td class="style3">
<asp:Panel ID="titlePanl" runat="server" >
<asp:TextBox ID="txtTitle0" runat="server"></asp:TextBox>
</asp:Panel>
</td>
<td class="style1">
<asp:Panel ID="videoFileUPControl" runat="server" >
<asp:FileUpload ID="FileUpload1" runat="server" />
</asp:Panel>
</td>
<td valign="top">
<!--
<input ID="btnAddOther" type="button" value="添加视频" onclick="return btnAddOther_onclick()" />
-->
<asp:Button ID="btnAddOther" runat="server" Text="添加视频"
onclick="btnAddOther_Click" />
<asp:Button ID="btnSub" runat="server" onclick="btnSub_Click" Text="减少" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
<asp:Button ID="btnUPload" runat="server" Text="上传" OnClientClick="if( !CheckForm()){setTimeout(ClearErrMessageLable ,6000);return false}" onclick="btnUPload_Click" />
</td>
<td class="style1">
<asp:Button ID="Button1" runat="server" Text="重置"
onclick="Button1_Click" />
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>