2010-07-21 5 views
2

내 5 가지 질문에 jquery validate plugin을 사용하려고합니다. 하지만 난 필드에 대한 유효성을 검사 한 오류 메시지를 표시하는 방법에 문제가 있습니다.Jquery가 오류 메시지 배치 위치를 확인합니다.

<form id="quiz"> 
<table width="100%"> 
<tbody> 
<tr id="qntr"> 
    <td id="qntd">My question 1</td> 
    <!-- if field is empty, validate error message to appear over here --> 
</tr> 
<tr id="anstr"> 
    <td id="anstd"> 
    <table><tr> 
     <td>Choice 1</td> 
     <td>Choice 2</td> 
     <td>Choice 3</td> 
    </tr></table> 
    </td> 
</tr> 
<tr id="qntr"> 
    <td id="qntd">My question 2</td> 
    <!-- if field is empty, validate error message to appear over here --> 
</tr> 
<tr id="anstr"> 
    <td id="anstd"> 
    <table><tr> 
     <td>Choice 1</td> 
     <td>Choice 2</td> 
     <td>Choice 3</td> 
    </tr></table> 
    </td> 
</tr> 
... 
</tbody> 
</table> 
</form> 

내 validate.js :

내 양식이 같은 것입니다

$(document).ready(function() { 
     var form = $("#quiz"); 
     form.validate({ 

      errorPlacement: function(error, element) { 
       error.insertAfter(x); // what should x be? 
      } 

     }); 

}); 

싶습니다 내 유효성 검사 오류에 대한 'X'는 errorPlacement에 대체하는 데 사용되어야 하는지를 양식의 에 표시 할 메시지가 있습니까?

감사합니다.

+0

두 개 이상의 요소에 동일한 ID를 사용하지 말 것을 강력히 권합니다. 아래 업데이트 된 답변을 확인하십시오! – dejavu

답변

3

UPDATE 여기

내 업데이트 솔루션입니다 :

error.appendTo(element.parents('#anstr').prev('tr')); 

ORIGINAL POST는

당신은 시도 했습니까?

error.insertAfter(element); 
+0

안녕하세요 dejavu, error.insertAfter (요소)를 사용하려고했지만 원하는 위치 대신 Choice 1 라디오 버튼 안에 표시됩니다. –

+0

내 게시물을 업데이트했습니다. 내 새로운 대답을 확인하십시오. – dejavu

+0

감사합니다. 작동합니다! –