我估计很多正在学习css,js的朋友们也有这样的经历,刚在做这个js切换的时候,我想到了一个好的方法,马上给大家分享一下,希望你们能把它拿走
复制代码 代码如下:
function changeDiv(index)
{
for(var i=0;i<=5;i++)
{
if(i == index)
document.getElementById('dv_'+i).className="txt1";
else
document.getElementById('dv_'+i).className="txt2";
}
}
可样子大家可能看的不是很清楚,这样 吧,我把html也贴出来了,大家就看看吧,
复制代码 代码如下:
<table width="100%" height="616" border="0" align="center" cellpadding="0" cellspacing="5" bgcolor="#FEFDF8">
<tr>
<td height="20">会员注册</td>
</tr>
<tr>
<td valign="top" bgcolor="#FEFDF8">
<table height="20"><tr><td></td></tr></table>
<table width="100%" height="300" border="0" cellpadding="0" cellspacing="10">
<tr>
<td width="100" align="right">会员名:</td>
<td><asp:TextBox CssClass="txt" id="txt_name" onfocus="changeDiv(0)" onblur="cheaked();check_callback()" runat="server"/><div id="showState"></div></td>
<td><div id="dv_0">5-20个字符(包括小写字母、数字、下划线、中文)</div></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><asp:TextBox id="txt_pwd" TextMode="Password" CssClass="txt" onfocus="changeDiv(1)" runat="server"/></td>
<td><div id="dv_1">请使用英文字母加数字或符号的组合密码</div></td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td><asp:TextBox id="txt_pwd1" TextMode="Password" CssClass="txt" onfocus="changeDiv(2)" runat="server"/></td>
<td><div id="dv_2">请重新输入密码</div></td>
</tr>
<tr>
<td align="right">电子邮箱:</td>
<td><asp:TextBox id="txt_mail" CssClass="txt" onfocus="changeDiv(3)" runat="server"/></td>
<td><div id="dv_3">请输入常用电子邮箱</div></td>
</tr>
<tr>
<td align="right">QQ/电话:</td>
<td><asp:TextBox id="txt_tel" CssClass="txt" onfocus="changeDiv(4)" runat="server"/></td>
<td><div id="dv_4">请填写您的QQ/电话号</div></td>
</tr>
<tr>
<td align="right">验证码:</td>
<td><asp:TextBox id="txt_vali" CssClass="txt" Width="150" onfocus="changeDiv(5)" runat="server"/><img id="vcodeimg" src="tools/verifyimage.aspx" title="点击刷新验证码" align="absmiddle" /><div id="showErro" runat=server></div></td>
<td><div id="dv_5">请输入验证码</div></td>
</tr>
<tr>
<td colspan="2" align="center"><INPUT type="checkbox" name="check_agreement">
<A href="#">我已阅读并同意会员条款</A></td>
<td align="center" valign="bottom"><asp:Button runat="server" ID="btn_register" onclientclick="return vipRegister()" Text="会员注册"/></td>
</tr>
</table></td>
</tr>
</table>