Compare radio button values using jquery

雨燕双飞 提交于 2020-08-06 06:39:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!