2015-04-23 154 views
1

我有这样jQuery验证消息问题

<input type="radio" name="specific_parent" id="parent_one" class="radio" value="existing_parent"><label class="redio_label" for="existing_parent">Existing Parent</label> 
<input type="radio" name="specific_parent" id="parent_two" class="radio" value="prospective_parent"><label class="redio_label" for="prospective_parent">Prospective Parent</label> 
<input type="radio" name="specific_parent" id="parent_third" class="radio" value="other"><label class="redio_label" for="other">Other</label> 

我已经申请jQuery验证这样三个输入单选按钮:

rules: { 
    specific_parent: { 
     required: true 
    } 
}, 
messages: { 
    specific_parent: { 
     required: 'Please select radio button' 
    } 
} 

问题是,它显示第一输入单选按钮后的错误消息,并我的布局是休息。

enter image description here

+0

你想在哪里显示它? – ozil

+0

你正在使用什么验证插件? – davidkonrad

+0

下所有三个单选按钮! – Iffi

回答

1

使用errorPlacement

errorPlacement: function (error, element) { 
     error.insertBefore(element); 
} 
+0

是否有像insertBefore()这样的元素后面的错误? – Iffi

+0

是的,有函数error.insertBefore(element)和error.insertAfter(element); –

+0

真棒工作!谢谢 – Iffi

0
<div class="input-container"> 
<input type="radio" name="specific_parent" id="parent_one" class="radio" value="existing_parent"><label class="redio_label" for="existing_parent">Existing Parent</label> 
<input type="radio" name="specific_parent" id="parent_two" class="radio" value="prospective_parent"><label class="redio_label" for="prospective_parent">Prospective Parent</label> 
<input type="radio" name="specific_parent" id="parent_third" class="radio" value="other"><label class="redio_label" for="other">Other</label> 
</div> 
<style type="text/css"> 
.input-container{position:relative;} 
</style> 

你必须添加输入你的父母DIV的CSS然后换用现在的位置绝对在CSS和使用上,左的错误信息的位置或底部属性,你可以调整你想要显示的位置。