送信ボタンを無効にして開始できます。
<input id="1" type="radio" name="1" value="1" />
<input id="2" type="radio" name="2" value="2" />
<input type="submit" disabled name="submit" value="valj" />
次に、スクリプトを使用してラジオ ボタンの変更イベントにバインドし、それらの値を調べて、必要に応じて無効化された属性を削除します。
// cache reference to all radio buttons.
var $radioButtons = $("input:radio");
$radioButtons.change(function(){
var anyRadioButtonHasValue = false;
// iterate through all radio buttons
$radioButtons.each(function(){
if(this.checked){
// indicate we found a radio button which has a value
anyRadioButtonHasValue = true;
// break out of each loop
return false;
}
});
// check if we found any radio button which has a value
if(anyRadioButtonHasValue){
// enable submit button.
$("input[name='submit']").removeAttr("disabled");
}
else{
// else is kind of redundant unless you somehow can clear the radio button value
$("input[name='submit']").attr("disabled", "");
}
});
DEMO - ラジオ ボタンが選択されている場合、ボタンを有効にします。