问题
In MVC 4 i am trying one scenario, i have 2 radio button sets,first set have the value of one,two three,four and second set consist of values one,two,three,four.When i select one in the first set the radiobutton holding value one in the second set should be disabled. I did like
$(document).ready(function () {
var EValue;
var MValue;
EValue = $("input:radio[name=E_message]:checked").val();
//Could be something like
Mvalue = $("input:radio[name=M_message]).val();
if(EValue == MValue){
$("input:radio[name=M_message]").attr("disabled", "disabled");
}
});
回答1:
html is
set 1</br>
<input type="radio" name="set1" value="1" />
<input type="radio" name="set1" value="2" />
<input type="radio" name="set1" value="3" />
<input type="radio" name="set1" value="4" />
<br/>
set2</br>
<input type="radio" name="set2" value="1" />
<input type="radio" name="set2" value="2" />
<input type="radio" name="set2" value="3" />
<input type="radio" name="set2" value="4" />
and javascript is
$('input[name=set1]').click(function() {
$('input[name=set2]').prop({disabled:false});
$('input[name=set2][value='+$(this).val()+']').prop({disabled:true});
});
$('input[name=set2]').click(function() {
$('input[name=set1]').prop({disabled:false});
$('input[name=set1][value='+$(this).val()+']').prop({disabled:true});
});
and js fiddle is http://jsfiddle.net/as245/
回答2:
Try this:
$(document).ready(function () {
var EValue;
var MValue;
EValue = $("input:radio[name='E_message']:checked").val();
//COuld be something like
Mvalue = $("input:radio[name='M_message']").val();//syntax error here
if(EValue == MValue)
{
$("input:radio[name='M_message']").attr("disabled", "disabled");//also use single quotes
}
});
You have adde extra });
here
来源:https://stackoverflow.com/questions/20840424/compare-radio-button-values-using-jquery