使用jQuery比较单选按钮的值 [英] Compare radio button values using jquery

查看:98
本文介绍了使用jQuery比较单选按钮的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC 4中,我正在尝试一种情况,我有2个单选按钮集,第一组的值分别为1、2、3、4,第二组的值分别为1、2、3、4.当我在其中选择一个时第一组应该禁用第二组中的单选按钮保持值. 我喜欢

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");
            }
 });

推荐答案

html是

 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" />

而javascript是

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});
});

和js小提琴是 http://jsfiddle.net/as245/

这篇关于使用jQuery比较单选按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆