フォームに複数のラジオ ボタンがあります。ページの送信時にそれらを検証したかったのです。ページの送信時に、ラジオ ボタンがチェックされていない場合、そのラジオ ボタンの 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>
Jクエリ
$(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/
どんな助けでも大歓迎です。