checkbox 选中,后面的多个textarea提示必填,高手帮忙

efanlx 2013-08-11 09:21:09

checkbox 选中,后面的多个textarea提示必填,由于那些事项都是从数据库里读出来的,个数无限制的。
请高手帮忙解决。急!分不是问题,解决后,可以另开贴奖分。感谢!

<tr>
<td bgcolor="#FFFFFF" class="f_c">事项<Input type="hidden" name="id_1" id="id_1" value="2"></td>
<td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
<tr>
<td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_1[]" id="id_1" value="A">  A、项目1</td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="B">  B、项目2</td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="C">  C、项目3</td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" class="f_c">成效<Input type="hidden" name="id_2" id="id_2" value="2"></td>
<td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
<tr>
<td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_2[]" id="id_2" value="A">  A、成效1</td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_2[]" id="xtgn_2" value="B">  B、成效2</td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
<td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
</tr>
</table>
</td>
</tr>


</table>
...全文
375 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
efanlx 2013-08-12
  • 打赏
  • 举报
回复
有木有办法 <form method="post" action="xxx.php" enctype="multipart/form-data" name="form" onSubmit="javascript:return check(this)"> 这样写?
efanlx 2013-08-12
  • 打赏
  • 举报
回复
在同一表单里,我还有一些<input name="name" type="text" id="name" size="10" class="box">要验证,这个又该如何加呀?我在网上找了一些资料,然后跟你这个结合起来,又用不了了。
fzfei2 2013-08-12
  • 打赏
  • 举报
回复
是可以这么写
efanlx 2013-08-12
  • 打赏
  • 举报
回复
帮忙解决后,这个贴,还有另外一个贴,我再另开一个贴,给你分奖。老大好人!
efanlx 2013-08-12
  • 打赏
  • 举报
回复
大哥,小弟会记住你的。 老大,我这样写可不可以? if(!check()){alert( "项目为必填!" ); }else{ window.location.href="xx.htm"; }
efanlx 2013-08-12
  • 打赏
  • 举报
回复
js 我一点都不懂的
fzfei2 2013-08-12
  • 打赏
  • 举报
回复
if(!check() )alert( "项目为必填!" ); #8写错了 多了个 “)", 楼主要好好补下JS基本东西
efanlx 2013-08-12
  • 打赏
  • 举报
回复
加上去了,有个小叹号,不行呀?
fzfei2 2013-08-12
  • 打赏
  • 举报
回复
if(!check()) alert( "项目为必填!") );
efanlx 2013-08-12
  • 打赏
  • 举报
回复
还有提示true时;就不用提示了,直接跳到加一页面去处理提交的数据了。
efanlx 2013-08-12
  • 打赏
  • 举报
回复
fzfei2 : 还有点问题,提示false和true,改成中文提示,如何修改? 我加alert("项目为必填!");然后就不提示了。
fzfei2 2013-08-12
  • 打赏
  • 举报
回复
引用 16 楼 efanlx 的回复:
有木有办法 <form method="post" action="xxx.php" enctype="multipart/form-data" name="form" onSubmit="javascript:return check(this)"> 这样写?
写了简单例子你参考一下

<style>
    .tip{
        height:20px;
        color:red;
        display:block;
        width:150px;
        font-size:12px;
        font-weight: normal;
        text-align:center;
    }
     
</style>
 
 

<form method="post" action="xxx.php" enctype="multipart/form-data" name="form" onSubmit="javascript:return Submit(this)">
	
name:<input name="name" type="text" id="name" size="10" class="box">

<table id="tb1" >
  <tr>
    <td bgcolor="#FFFFFF" class="f_c">事项<input type="hidden" name="id_1" id="id_1" value="2" /></td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_1[]" id="id_1" value="A">  A、项目1 <b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="B">  B、项目2<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="C">  C、项目3<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="f_c">成效<Input type="hidden" name="id_2" id="id_2" value="2"></td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_2[]" id="id_2" value="A">  A、成效1<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_2[]" id="xtgn_2" value="B">  B、成效2<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>
</table> 
 
 
<input type=submit value="提交"  />

</form>
  
<script>
    var tb=document.getElementById('tb1');
    var chs=[],_chs=tb.getElementsByTagName('input');
    var texts=tb.getElementsByTagName('textarea');
    var tips=tb.getElementsByTagName('b'),idx=0;
    function trim(s){ return s.replace(/^\s*|\s*$/g,'') };
    for(var i=0;i<_chs.length;i++) if(_chs[i].type=='checkbox') {
        _chs[i].i=idx++;
        _chs[i].onclick=function(){ tips[this.i].innerHTML=this.checked?'所有项目为必填':''  }
        chs.push(_chs[i])
    }
    function check(){
         var r=chs.length,c=texts.length/r;
         while(r--){
             for(var i=0;chs[r].checked&&i<c;i++)
                   if(!trim(texts[ r*c+i].value) ) return false;
         }
     return true;
 }
 function Submit(f){
 	if(!check()  ){
 		alert('选中事项xxxx不能为空');
 		return false;
 	}else if( f.name.value=="" ){
		alert('name不能为空');
 		return false;
  }
  
  return true;
 }
  
</script>
efanlx 2013-08-11
  • 打赏
  • 举报
回复
to fzfei2 : 如果能加上checkbox选择后,提示选择的事项名称下的所有项目为必填,这样就更好了
街头小贩 2013-08-11
  • 打赏
  • 举报
回复

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<title>无标题文档</title>
</head>

<body>
<table>
<tr>
    <td bgcolor="#FFFFFF" class="f_c">事项<Input type="hidden" name="id_1" id="id_1" value="2"></td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_1[]" id="id_1" value="A">  A、项目1</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea  name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="B">  B、项目2</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="C">  C、项目3</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="f_c">成效<Input type="hidden" name="id_2" id="id_2" value="2"></td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_2[]" id="id_2" value="A">  A、成效1</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_2[]" id="xtgn_2" value="B">  B、成效2</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>


</table> 
<script type="text/javascript">
	$(':checkbox').click(function(){
		var status=this.checked;
		if(status){
			$(this).parent().parent().find('textarea').attr('placeholder','项目相关描述必填噢');	
		}else{
			$(this).parent().parent().find('textarea').removeAttr('placeholder');	
		}	
	});
</script>
</body>
</html>

fzfei2 2013-08-11
  • 打赏
  • 举报
回复
是这样?,你参考一下


<table id="tb1" >
  <tr>
    <td bgcolor="#FFFFFF" class="f_c">事项<input type="hidden" name="id_1" id="id_1" value="2" /> </td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_1[]" id="id_1" value="A">  A、项目1</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="B">  B、项目2</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="C">  C、项目3</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="f_c">成效<Input type="hidden" name="id_2" id="id_2" value="2"></td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_2[]" id="id_2" value="A">  A、成效1</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_2[]" id="xtgn_2" value="B">  B、成效2</td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>
</table> 
<input type=button value="test" onclick="Submit()" />

<script>
	var tb=document.getElementById('tb1');
	var chs=[],_chs=tb.getElementsByTagName('input');
	var texts=tb.getElementsByTagName('textarea');
	function trim(s){ return s.replace(/^\s*|\s*$/g,'') };
	for(var i=0;i<_chs.length;i++) if(_chs[i].type=='checkbox') chs.push(_chs[i])
	function check(){
	 	var r=chs.length,c=texts.length/r;
	 	while(r--){
	 		for(var i=0;chs[r].checked&&i<c;i++)
	 			  if(!trim(texts[ r*c+i].value) ) return false
	 	}
	 return true;
 }
 
 function Submit(){
  alert(	check()   );
 }
 
</script>
fzfei2 2013-08-11
  • 打赏
  • 举报
回复
你有用JQ?
fzfei2 2013-08-11
  • 打赏
  • 举报
回复
引用 4 楼 efanlx 的回复:
to fzfei2 : 如果能加上checkbox选择后,提示选择的事项名称下的所有项目为必填,这样就更好了
为了简单 要在 项目名称后都直接加<b class="tip" ></b> 如果就支持HTML5下, #3 xiaofanku的方法很不错

<style>
	.tip{
		height:20px;
		color:red;
		display:block;
		width:150px;
		font-size:12px;
		font-weight: normal;
		text-align:center;
	}
	
</style>

<table id="tb1" >
  <tr>
    <td bgcolor="#FFFFFF" class="f_c">事项<input type="hidden" name="id_1" id="id_1" value="2" /></td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_1[]" id="id_1" value="A">  A、项目1 <b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="B">  B、项目2<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_1[]" id="xtgn_1" value="C">  C、项目3<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_1" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="f_c">成效<Input type="hidden" name="id_2" id="id_2" value="2"></td>
    <td bgcolor="#FFFFFF" colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c7e9ff">
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="id_2[]" id="id_2" value="A">  A、成效1<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
  <tr>
    <td bgcolor="#FFFFFF" width="35%"><input type="checkbox" name="xtgn_2[]" id="xtgn_2" value="B">  B、成效2<b class="tip" ></b></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="name_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="24%"><textarea name="bsfs_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
    <td bgcolor="#FFFFFF" width="17%"><textarea name="synx_2" class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+16)+'px');overflow:auto;"></textarea></td>
 </tr>
 </table>
</td>
  </tr>
</table> 



<input type=button value="test" onclick="Submit()" />
 
 
<script>
	var tb=document.getElementById('tb1');
	var chs=[],_chs=tb.getElementsByTagName('input');
	var texts=tb.getElementsByTagName('textarea');
	var tips=tb.getElementsByTagName('b'),idx=0;
	function trim(s){ return s.replace(/^\s*|\s*$/g,'') };
	for(var i=0;i<_chs.length;i++) if(_chs[i].type=='checkbox') {
		_chs[i].i=idx++;
		_chs[i].onclick=function(){ tips[this.i].innerHTML=this.checked?'所有项目为必填':''  }
		chs.push(_chs[i])
	}
	function check(){
	 	var r=chs.length,c=texts.length/r;
	 	while(r--){
	 		for(var i=0;chs[r].checked&&i<c;i++)
	 			  if(!trim(texts[ r*c+i].value) ) return false;
	 	}
	 return true;
 }
 function Submit(){
  alert(	check()   );
 }
 
</script>

61,114

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧