チェックボックスを含むフォームがあり、最初のチェックボックスがユーザーによってチェックされているかどうかを確認したい:
<form id= 'other_langs'>
<input type= 'checkbox' name= 'yes'> I speak other languages <br>
<input type= 'checkbox' name= 'no'> I do <b>not</b> speak any other language <br>
</form>
そして私はjQuery関数を書きました
$('#other_langs').click(function(){
if(('#other_langs').first().prop('checked') == true){alert('ok');}
});
アラート (または何でも) は表示されません。.is(':checked') も試しましたが、同じです。私も試しました
if(('#other_langs input[name="yes"]').prop('checked') == true){alert('ok');}
jQuery バージョン 1.9.1 を使用しており、Firefox と Chrome の両方を試しました。