2012-10-12 88 views
2

我有一个带单选按钮的基本表。即使在点击“td”时检查收音机的“td”中,我也有一个onclick。单击“td”时,错误消息不会隐藏。它只在实际按钮被点击时隐藏。这是我的代码。有任何想法吗?我有本地存储的jquery文件。jquery验证插件隐藏错误消息

<html> 
    <head> 
     <script src="jquery-latest.js"></script> 
     <script type="text/javascript" src="jquery.validate.js"></script> 
    <script> 
     $(document).ready(function(){ 
      $("#myform").validate({ 
      errorPlacement: function(error, element) { 
        error.appendTo(element.parent("td").prev("td")); 
      }, 
      debug:true 
     }) 
    }); 

    </script> 
</head> 

<body> 
<form id="myform" action="/login" method="post"> 
<table border="1"> 
<tr> 
    <td width="30%">Attribute 1<br /></td> 
     <td width="10%" onclick="$(this).find('input:radio').attr('checked','checked');" /><INPUT type="radio" id="22121GRID" name="SPGRID_1" value="5" class="required" /></td> 
     <td width="10%" onclick="$(this).find('input:radio').attr('checked','checked');" /><INPUT type="radio" id="22121GRID" name="SPGRID_1" value="4" class="required" /></td> 
     <td width="10%" onclick="$(this).find('input:radio').attr('checked','checked');" /><INPUT type="radio" id="22121GRID" name="SPGRID_1" value="3" class="required" /></td> 
     <td width="10%" onclick="$(this).find('input:radio').attr('checked','checked');" /><INPUT type="radio" id="22121GRID" name="SPGRID_1" value="2" class="required" /></td> 
     <td width="10%" onclick="$(this).find('input:radio').attr('checked','checked');" /><INPUT type="radio" id="22121GRID" name="SPGRID_1" value="1" class="required" /></td> 
</tr> 
<tr><td><input type="submit" value="Submit" /></td></tr> 
</table> 
</form> 


</body> 
</html> 

回答

1

由于您更改通过javascript检查,请致电.valid()验证方法。

您可以使用以下

<td width="10%" onclick="$(this).find('input:radio').attr('checked','checked').valid();" />   <INPUT type="radio" id="22121GRID" name="SPGRID_1" value="5" class="required" /> </td> 

$('td').click(function(){ 
$(this).find('radio').attr('checked','checked').valid(); 
});