我在一个表单中有多个单选按钮。我正在验证那些提交表单的人。因此,如果未选择单选按钮,它将显示该单选按钮的标题属性中给出的错误。不同单选按钮的标题不同。这个显示错误现在工作正常。现在,当用户检查单选按钮时,我需要删除该错误消息。但这不起作用
HTML
<div class="input-container" data-validation="required">
<input type="radio" name="radio1" id="first" value="First" class="required "title="Please select first to continue."/>
<label for="first">First</label>
<br/>
<input type="radio" name="radio1" id="second" value="Second" class="required "title="Please select first to continue."/>
<label for="second">Second</label>
</div>
<hr/>
<div class="input-container" data-validation="required">
<input type="radio" name="radio2" id="first" value="First" class="required "title="Please select second to continue."/>
<label for="first">First</label>
<br/>
<input type="radio" name="radio2" id="second" value="Second" class="required "title="Please select second to continue."/>
<label for="second">Second</label>
</div>
<hr/>
<button>Validate</button>
Javascript
$(function() {
$('button').click(function(){
$.each($('.input-container[data-validation=required]'), function (idx,group) {
var current = $(group).find(':radio');
if( !current.is(':checked') ) {
var title = current.attr('title');
$(group).next('ul.innererrormessages').remove();
$(group).after('<ul class="innererrormessages"><li>'+title+'</li></ul>');
}
});
});
$('.input-container .required').change(function(){
$(this).next('ul.innererrormessages').remove();
});
});