<table>
<tr>
<td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox8" runat="server"></asp:TextBox></td>
</tr>
</table>这样一个表格,第一行有4个textbox,第二行也有4个textbox,用户输入的时候,如果第一行只输入了3个textbox它就把焦点切换到了第二行,那么就aler("要么输入4个,要么一个都不输入"),如果一个都不输入,则不弹!
<tr>
<td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="TextBox8" runat="server"></asp:TextBox></td>
</tr>
</table>这样一个表格,第一行有4个textbox,第二行也有4个textbox,用户输入的时候,如果第一行只输入了3个textbox它就把焦点切换到了第二行,那么就aler("要么输入4个,要么一个都不输入"),如果一个都不输入,则不弹!
function $(sub1)
{
return document.getElementById (sub1);
}
function $$()
{
if(!TF())
{
alert("要么输入4个,要么一个都不输入");
}
}
function TF()
{
var a=0;
if($("TextBox1").value=="")
{
a++;
}
if($("TextBox2").value=="")
{
a++;
}
if($("TextBox3").value=="")
{
a++;
}
if($("TextBox4").value=="")
{
a++;
}
if(a>3||a<1)
{return true;}
else
{return false;}
}</script>
<body>
<form runat =server id=form1>
<table>
<tr>
<td> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </td> <td> <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> </td> <td> <asp:TextBox ID="TextBox3" runat="server"> </asp:TextBox> </td> <td> <asp:TextBox ID="TextBox4" runat="server"> </asp:TextBox> </td>
</tr>
<tr>
<td> <asp:TextBox ID="TextBox5" runat="server" onFocus="$$();"> </asp:TextBox> </td> <td> <asp:TextBox ID="TextBox6" runat="server" onFocus="$$();"> </asp:TextBox> </td> <td> <asp:TextBox ID="TextBox7" runat="server" onFocus="$$();"> </asp:TextBox> </td> <td> <asp:TextBox ID="TextBox8" runat="server" onFocus="$$();"> </asp:TextBox> </td>
</tr>
</table>
</form>
</body> </html>
<script type="text/javascript">
function checkPre(obj)
{
var row = obj.parentNode.parentNode;
var rIndex = row.rowIndex;
if(rIndex>0)
{
var preRow = row.parentNode.rows[rIndex-1];
var texts = preRow.getElementsByTagName("INPUT");
var icount=0;
for(i=0;i<texts.length;i++)
{
if(texts[i].value!="")
{
icount++;
}
}
if(icount>0 && icount<4)
{
alert("要么输入4个,要么一个都不输入");
}
}
}
</script>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"> </asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"> </asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox5" runat="server" onfocus="checkPre(this);"> </asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox6" runat="server" onfocus="checkPre(this);"> </asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox7" runat="server" onfocus="checkPre(this);"> </asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox8" runat="server" onfocus="checkPre(this);"> </asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
function getsum()
{
var items = document.getElementsByTagName("INPUT");
var elem;
for(var i = 0; i < items.length; i ++)
{
elem = items[i];
if(elem.type == "text")
{
elem.value="";
}
}
}
</script>
<script type="text/javascript">
function checkPre(obj)
{
var row = obj.parentNode.parentNode;
var rIndex = row.rowIndex;
if(rIndex>0)
{
var preRow = row.parentNode.rows[rIndex-1];
var texts = preRow.getElementsByTagName("INPUT");
var icount=0;
for(i=0;i<texts.length;i++)
{
if(texts[i].value!="")
{
icount++;
}
}
if(icount>0 && icount<4)
{
alert("上一行要么输入4个,要么一个都不输入");
//加下面的
for(i=0;i<texts.length;i++)
{
if(texts[i].value=="")
{
texts[i].focus();
break;//加完跳出循环
}
} }
}
}
</script>