以下是一段验证控件的代码,我的目的是想在button1的OnClientClick事件中写一些代码,来控制id为msg的DIV的class属性为.msg,各位请帮帮忙
<!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">
.msg{border:1px solid #FF8080;background-color:#FFC0C0;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="msg" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="请输入内容" ForeColor="">请输入内容</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="错误的电子邮件" ForeColor="" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">错误的电子邮件</asp:RegularExpressionValidator>
</div>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button OnClientClick="" ID="Button1" runat="server" Text="Button" />
</div>
</div>
</form>
</body>
</html>
<!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">
.msg{border:1px solid #FF8080;background-color:#FFC0C0;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="msg" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="请输入内容" ForeColor="">请输入内容</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="错误的电子邮件" ForeColor="" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">错误的电子邮件</asp:RegularExpressionValidator>
</div>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button OnClientClick="" ID="Button1" runat="server" Text="Button" />
</div>
</div>
</form>
</body>
</html>
解决方案 »
- 冰天雪地跪地求教
- asp.net发送电子邮件问题???
- 回调函数中的OpenModalDialogp被IE屏蔽了!
- 在IIS5.1中,剪切板无法使用
- 如何获取detailsview中控件的值
- 为什么这些方法在列表中无法直接选择?
- 请问各位大虾几个小问题!急!(我是菜鸟)
- 开启线程读取日志数据, 并插入mysql数据库 的问题。。
- 如何在ASP.NET的使用Activx控件
- 哈哈,总算升星星了,散分两百,以示庆祝!!
- 为何ObjectDataSource Selected事件中的e.AffectRows不起作用?
- 请讲一下asp.net需要多深的c#基础.再说一下可以同时学习java和ASP.NET吗?
{
if(!this.RequiredFieldValidator1.IsValid)
{
string script="<script>document.getElementById('msg').className='inp33'</script>";
Page.RegisterStartupScript("a",script);
}
}
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
<style type="text/css">
.msg{border:1px solid #FF8080;background-color:#FFC0C0;}
</style>
<script type="text/javascript">
function setClass()
{
if(RequiredFieldValidatorEvaluateIsValid(RequiredFieldValidator1)==false
|| RegularExpressionValidatorEvaluateIsValid(RegularExpressionValidator1)==false)
{
document.getElementById("msg").className = "msg";
return false;
}
else
{
document.getElementById("msg").className = "";
return true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="msg" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="请输入内容" ForeColor="">请输入内容</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="错误的电子邮件" ForeColor="" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">错误的电子邮件</asp:RegularExpressionValidator> </div>
<div id="liuliu">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button OnClientClick="setClass()" ID="Button1" runat="server" Text="Button" />
</div>
</div>
</form>
</body>
</html>