У меня есть несколько переключателей в форме. Я хотел подтвердить их при отправке страницы. При отправке страницы, если переключатели не отмечены, мне нужно отобразить сообщение об ошибке, указанное в атрибуте title этого переключателя. Название отличается для разных переключателей. Как я могу получить атрибут title этого переключателя, который не отмечен?
HTML
<div class="input-container" data-validation="required">
<input type="radio" name="radio1" id="first" value="First" class="required "title="Please select to continue."/>
<label for="first">First</label>
</div>
Jquery
$(function() {
$('button').click(function(){
$.each($('.input-container[data-validation=required]'), function (idx,group) {
var current = $(group).find('[type=radio]:checked').val();
alert(current);
if( current === undefined ) {
//I need to display the title as the error message
//like var title = current.attr('title');
$(group).after('<ul class="innererrormessages"><li>'+title+'</li></ul>');
}
});
});
});
Пожалуйста, найдите скрипт моего html
http://jsfiddle.net/jUQYr/15/
Любая помощь приветствуется.
$('button').click(function(){
$.each($('.input-container[data-validation=required]'), function (idx, el) {
var current = $(el).find(':radio');
if( !current.is(':checked') ) {
var title = current.attr('title');
$(el).after('<ul class="innererrormessages"><li>'+title+'</li></ul>');
}
});
});
$(function() {
$('button').click(function(){
$.each($('.input-container[data-validation=required]'), function (idx,group) {
var checked = $(group).find('[type=radio]:checked');
var unchecked = $(group).find('[type=radio]');
if(checked.length != unchecked.length ) {
$.each(unchecked, function(i,v) {
if($(v).attr('id') != $(checked[i]).attr('id')) {
//I need to display the title as the error message
var title = $(v).attr('title');
$(group).after('<ul class="innererrormessages"><li>'+title+'</li></ul>');
}
});
}
});
});
});
:not