Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用单选按钮选择隐藏/显示文本_Javascript_Jquery - Fatal编程技术网

Javascript 使用单选按钮选择隐藏/显示文本

Javascript 使用单选按钮选择隐藏/显示文本,javascript,jquery,Javascript,Jquery,我有3套单选按钮,我想显示一个文本,如果所有被选中,其值为真是。如果至少有1个值为false,则隐藏文本否 我的页面看起来像: Are you eligible for this? .Yes .No Are you paying your bills monthly? .Yes .No Do you have health insurance? .Yes .No 我想在jQuery中这样做,我已经在下面附上了我的代码 <div>Are

我有3套单选按钮,我想显示一个文本,如果所有被选中,其值为真是。如果至少有1个值为false,则隐藏文本否

我的页面看起来像:

 Are you eligible for this?           .Yes .No 
 Are you paying your bills monthly?   .Yes .No
 Do you have health insurance?        .Yes .No
我想在jQuery中这样做,我已经在下面附上了我的代码

<div>Are you eligible for this?</div>
           <div>
                <div>
                    <label for="yes">Yes</label> 
                    <input type="radio" name="mygroup" id="yes" value="true" />
                </div>
                <div>
                    <label for="no">No</label> 
                    <input type="radio" name="mygroup" id="no" value="false" />
                </div>
            </div>

            <div>Are you paying your bills monthly?</div>
            <div>
                <div>
                    <label for="yes1">Yes</label> 
                    <input type="radio" name="mygroup" id="yes1" value="true" />
                </div>
                <div>
                    <label for="no1">No</label> 
                    <input type="radio" name="mygroup" id="no1" value="false" />
                </div>
            </div>

            <div>Do you have health insurance?</div>
            <div>
                <div>
                    <label for="yes2">Yes</label> 
                    <input type="radio" name="mygroup" id="yes2" value="true" />
                </div>
                <div>
                    <label for="no2">No</label> 
                    <input type="radio" name="mygroup" id="no2" value="false" />
                </div>
            </div>
我们可以计算所选单选按钮的数量吗?

您可以使用onClick方法检查三个单选按钮是否都是真的。满足该条件后,只需将文本设置为按您希望的方式显示,例如x.style.display='none'


注意:这并不适用于免费编码,但如果有一个原则或错误您有困难,可以解决。

对不起,stackoverflow不是免费的代码编写服务。欢迎您提供一些帮助,但是如果您没有自己编写一些代码,您将无法获得任何支持。到目前为止,您尝试了什么?向我们展示您的代码,您将更有可能获得帮助。Check.$.class.eachfunction{if$this.attrvalue==true&&$this.is:checked{//show}else{//hide};我能够检查至少一个单选按钮是否已检查,但如何检查所有3个单选按钮并为真?$'input:radio:checked'。长度将返回检查的单选按钮数。假设页面上只有三个,那么只需检查所检查的金额是否为三。如果是这样,那么您可以运行更改显示值。太棒了!我很高兴它做到了:
$("input[name='mygroup']").change(function(){
    if($(this).attr("value")=="true" && $(this).is(":checked")){
             //show
    }else{
            //hide
    }
});