function deleteLine()
{
for (var i=tbody1.rows.length-1; i>=0 ; i-- )
if (tbody1.rows[i].cells[0].firstChild.checked){
var str = tbody1.rows[i].cells[1].firstChild.value;
if(str.indexOf(",")!= -1){
alert("输入中文包含,");
}else{
tbody1.deleteRow(i);
}
}
}
调试欢乐多
1.输入,不能含有逗号
2.数值
3.日期 谢谢
Easy Validate简易表单验证
http://topic.csdn.net/u/20081007/09/26060e37-865a-4247-93f3-70bf93427b70.html驗證規則可自行擴展!
function deleteLine()
{
for (var i=tbody1.children.length-1; i>=0 ; i-- )
if (tbody1.children[i].firstChild.firstChild.checked)
tbody1.deleteRow(i);
}
function addLine()
{
elm = thead1.lastChild.cloneNode(true)
elm.style.display="block";
tbody1.insertBefore(elm);
}
function check(f){
var row,cell
for(var i=0;i<tbody1.rows.length;i++){
row=tbody1.rows[i];
o=row.cells[1].firstChild;
if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
alert('品牌请输入中文并且不能含逗号!');
o.focus();
return false;
}
o=row.cells[2].firstChild;
if(o.value==""||isNaN(o.value)){
alert('数量为数量!');
o.focus();
return false;
}
o=row.cells[3].firstChild;
if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
alert('时间格式为2008-10-17,格式不正确!');
o.focus();
return false;
}
}
}
</script> <form method="post" onsubmit="return check(this)">
<TABLE cellSpacing=1 cellPadding=0 width="400" bgColor=#cccccc border=0><TBODY>
<thead id=thead1>
<TR bgColor=#f5f5f5 height=25>
<td height="30" colspan="4">行是动态增减, 文本框对应的要求是
1.输入中文,不能含有逗号
2.数值3.日期 .请高手告知js的前台验证. 万分感激:)</td>
</tr>
<TR bgColor=#f5f5f5 height=25>
<td width="38" height="30" align="center">选中</td>
<td width="163">品牌(中文不能有,号)</td>
<td width="82">数量(数值)</td>
<td width="112">要求时间(日期)</td>
</tr>
<TR bgColor=#ffffff height=25 style="display:none">
<td height="25"><input type=checkbox id=checkLine></td>
<td><INPUT name=brand id="brand" size=10 maxlength="50"></td>
<td><INPUT name=amount id="amount" size=6 maxlength="20"></td>
<td><INPUT name=datelimit id="datelimit" size=12 maxlength="50"></td>
</tr>
</thead>
<tbody id=tbody1>
<TR bgColor=#ffffff height=25>
<td height="25"><input type=checkbox id=checkLine></td>
<td><INPUT name=brand id="brand" size=10 maxlength="50"></td>
<td><INPUT name=amount id="amount" size=6 maxlength="20"></td>
<td><INPUT name=datelimit id="datelimit" size=12 maxlength="12"></td>
</tr>
</tbody>
<TR bgColor=#ffffff height=25>
<td height="25" colspan="4">
<input name="button2" type=button onclick="addLine()" value=添加 />
<input name="button4" type=button onclick="deleteLine()" value=删除 />
<input name="button4" type=submit value=提交 /></td>
</tr>
</table>
</form>
var o=$('checkLine');
if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
alert('品牌请输入中文并且不能含逗号!');
o.focus();
return false;
}
}
<input type="text" id="checkLine" onblur="check()"/>
正在测试中,这句能不能改为不能为空且不能含逗号,如何更改?
}
最后一个问题。
在该表单下,还有一个文本框。(不在动态行里)也需要验证下,不能为空。
<input name="sltClient" type="text" id="sltClient" size="30" maxlength="50" >
再次showbo感谢. 测试完成后,立马给分.
<form ...>
...
<input name="sltClient" type="text" id="sltClient" size="30" maxlength="50" > (如何验证 不能为空?)
...
动态行文本框 ( 这里的验证已经ok了 )
....
</form>
}
}我回复怎么没了呢?
//使用onsubmit="return check(this)"传递进来的表单对象获取sltClient这个控件
if(/^\s*$/.test(f.sltClient.value)){
alert("sltClient不能为空!");f.sltClient.focus();return false;
}
//=============
/*其他验证代码*/
}
<script>
function deleteLine()
{
for (var i=tbody1.children.length-1; i>=0 ; i-- )
if (tbody1.children[i].firstChild.firstChild.checked)
tbody1.deleteRow(i);
}
function addLine()
{
elm = thead1.lastChild.cloneNode(true)
elm.style.display="block";
tbody1.insertBefore(elm);
}
function check(f){
var row,cell
for(var i=0;i<tbody1.rows.length;i++){
row=tbody1.rows[i];
o=row.cells[1].firstChild;
if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
alert('备注不能含逗号!');
o.focus();
return false;
}
o=row.cells[2].firstChild;
if(o.value==""||isNaN(o.value)){
alert('数量为数量!');
o.focus();
return false;
}
o=row.cells[3].firstChild;
if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
alert('时间格式为2008-10-17,格式不正确!');
o.focus();
return false;
}
}
}
</script> <form method="post" onsubmit="return check(this)">
<TABLE cellSpacing=1 cellPadding=0 width="400" bgColor=#cccccc border=0><TBODY>
<thead id=thead1>
<TR bgColor=#f5f5f5 height=25>
<td height="30" colspan="4"> 文本框对应的要求是
1文本框客户也验证,不能为空. 行是动态增减,2备注可以为空,如果有内容不能含有逗号
万分感激:)</td>
</tr>
<TR bgColor=#f5f5f5 height=25>
<td height="30" colspan="4" align="center">客户
<input name="sltClient" type="text" id="sltClient" size="10" maxlength="20" ></td>
</tr>
<TR bgColor=#f5f5f5 height=25>
<td width="38" height="30" align="center">选中</td>
<td width="163">备注(可以为空,如果有内容不能有,号)</td>
<td width="82">数量(数值)</td>
<td width="112">要求时间(日期)</td>
</tr>
<TR bgColor=#ffffff height=25 style="display:none">
<td height="25"><input type=checkbox id=checkLine></td>
<td><INPUT name=brand id="brand" size=10 maxlength="50"></td>
<td><INPUT name=amount id="amount" size=6 maxlength="20"></td>
<td><INPUT name=datelimit id="datelimit" size=12 maxlength="50"></td>
</tr>
</thead>
<tbody id=tbody1>
<TR bgColor=#ffffff height=25>
<td height="25"><input type=checkbox id=checkLine></td>
<td><INPUT name=brand id="brand" size=10 maxlength="50"></td>
<td><INPUT name=amount id="amount" size=6 maxlength="20"></td>
<td><INPUT name=datelimit id="datelimit" size=12 maxlength="12"></td>
</tr>
</tbody>
<TR bgColor=#ffffff height=25>
<td height="25" colspan="4">
<input name="button2" type=button onclick="addLine()" value=添加 />
<input name="button4" type=button onclick="deleteLine()" value=删除 />
<input name="button4" type=submit value=提交 /></td>
</tr>
</table>
</form>1文本框客户也验证,不能为空. 行是动态增减,2备注可以为空,如果有内容不能含有逗号
function check(f){
//使用onsubmit="return check(this)"传递进来的表单对象获取sltClient这个控件
if(/^\s*$/.test(f.sltClient.value)){
alert("sltClient不能为空!");f.sltClient.focus();return false;
}
//=============
/*其他验证代码*/
}这个还是没调试出来。
<script>
function deleteLine()
{
for (var i=tbody1.children.length-1; i>=0 ; i-- )
if (tbody1.children[i].firstChild.firstChild.checked)
tbody1.deleteRow(i);
}
function addLine()
{
elm = thead1.lastChild.cloneNode(true)
elm.style.display="block";
tbody1.insertBefore(elm);
}
function check(f){
//===========================================================================
//使用onsubmit="return check(this)"传递进来的表单对象获取sltClient这个控件
if(/^\s*$/.test(f.sltClient.value)){
alert("客户不能为空!");f.sltClient.focus();return false;
}
//===========================================================================
var row,cell
for(var i=0;i<tbody1.rows.length;i++){
row=tbody1.rows[i];
o=row.cells[1].firstChild;
if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
alert('备注不能含逗号!');
o.focus();
return false;
}
o=row.cells[2].firstChild;
if(o.value==""||isNaN(o.value)){
alert('数量为数量!');
o.focus();
return false;
}
o=row.cells[3].firstChild;
if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
alert('时间格式为2008-10-17,格式不正确!');
o.focus();
return false;
}
}
}
</script> <form method="post" onsubmit="return check(this)">
<TABLE cellSpacing=1 cellPadding=0 width="400" bgColor=#cccccc border=0><TBODY>
<thead id=thead1>
<TR bgColor=#f5f5f5 height=25>
<td height="30" colspan="4"> 文本框对应的要求是
1文本框客户也验证,不能为空. 行是动态增减,2备注可以为空,如果有内容不能含有逗号
万分感激:)</td>
</tr>
<TR bgColor=#f5f5f5 height=25>
<td height="30" colspan="4" align="center">客户
<input name="sltClient" type="text" id="sltClient" size="10" maxlength="20" ></td>
</tr>
<TR bgColor=#f5f5f5 height=25>
<td width="38" height="30" align="center">选中</td>
<td width="163">备注(可以为空,如果有内容不能有,号)</td>
<td width="82">数量(数值)</td>
<td width="112">要求时间(日期)</td>
</tr>
<TR bgColor=#ffffff height=25 style="display:none">
<td height="25"><input type=checkbox id=checkLine></td>
<td><INPUT name=brand id="brand" size=10 maxlength="50"></td>
<td><INPUT name=amount id="amount" size=6 maxlength="20"></td>
<td><INPUT name=datelimit id="datelimit" size=12 maxlength="50"></td>
</tr>
</thead>
<tbody id=tbody1>
<TR bgColor=#ffffff height=25>
<td height="25"><input type=checkbox id=checkLine></td>
<td><INPUT name=brand id="brand" size=10 maxlength="50"></td>
<td><INPUT name=amount id="amount" size=6 maxlength="20"></td>
<td><INPUT name=datelimit id="datelimit" size=12 maxlength="12"></td>
</tr>
</tbody>
<TR bgColor=#ffffff height=25>
<td height="25" colspan="4">
<input name="button2" type=button onclick="addLine()" value=添加 />
<input name="button4" type=button onclick="deleteLine()" value=删除 />
<input name="button4" type=submit value=提交 /></td>
</tr>
</table>
</form>
if(/^\s*$/.test(f.sltClient.value)){
alert("客户不能为空!");f.sltClient.focus();return false;
} var row,cell
for(var i=0;i<tbody1.rows.length;i++){
row=tbody1.rows[i];
o=row.cells[1].firstChild; if(o.value!=""&&/[,,]/g.test(o.value)){//=========================
alert('备注不能含逗号!');
o.focus();
return false;
}
o=row.cells[2].firstChild;
if(o.value==""||isNaN(o.value)){
alert('数量为数量!');
o.focus();
return false;
}
o=row.cells[3].firstChild;
if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
alert('时间格式为2008-10-17,格式不正确!');
o.focus();
return false;
}
}
}
alert('备注不能含逗号!');
备注可以空,但不能含逗号怎么改?
if(!o.value==""&&/[,,]/g.test(o.value)){
我自己改了下你看行吗if(!o.value==""&&/[,,]/g.test(o.value)){