Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Jquery 使用另一个单选选项切换单选选项,刷新按钮不显示页面_Jquery_Jquery Ui_Radio Button_Toggle_Jquery Mobile - Fatal编程技术网

Jquery 使用另一个单选选项切换单选选项,刷新按钮不显示页面

Jquery 使用另一个单选选项切换单选选项,刷新按钮不显示页面,jquery,jquery-ui,radio-button,toggle,jquery-mobile,Jquery,Jquery Ui,Radio Button,Toggle,Jquery Mobile,好的,我有一张表格,上面有一些问题作为单选选项。如果选择第一个收音机作为选项yes(是),则显示第二个收音机选项。如果第二个单选选项也选择“是”作为选项,则显示第三个元素(文本框) 此功能正在工作,但我无法工作的是,如果他们将第一个单选选项更改为“否”,如何隐藏和取消设置第二个单选选项(将选项设置为“否”),以及清除和隐藏第三个元素(文本框)值 以下是我尝试过的: $("#second_radio_div").hide("fast"); $("#third_element_div").hide(

好的,我有一张表格,上面有一些问题作为单选选项。如果选择第一个收音机作为选项yes(是),则显示第二个收音机选项。如果第二个单选选项也选择“是”作为选项,则显示第三个元素(文本框)

此功能正在工作,但我无法工作的是,如果他们将第一个单选选项更改为“否”,如何隐藏和取消设置第二个单选选项(将选项设置为“否”),以及清除和隐藏第三个元素(文本框)值

以下是我尝试过的:

$("#second_radio_div").hide("fast");
$("#third_element_div").hide("fast");

$("[name=first_radio]").change(function(){
    $("#second_radio_div").toggle($("[name=first_radio]").index(this)===1);

    if($("[name=first_radio]").index(this)===0) {
        //$('input:radio[name="second_radio_no"]').attr('checked',true); 
        //$('#second_radio').buttonset("refresh");
        //$('[name="second_radio"][value="no"]').attr("checked", true);
        //$('#second_radio').buttonset("refresh");
        $("#third_element_div").hide("fast"); // This works to hide the element
    }
});

$("[name=second_radio]").change(function(){
    $("#third_element_div").toggle($("[name=second_radio]").index(this)===1);
});
HTML

<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
    <div>First Radio</div>
        <input type="radio" name="first_radio" id="first_radio_yes" value="yes" />
        <label for="first_radio_yes">Yes</label>

        <input type="radio" name="first_radio" id="first_radio_no" value="no" checked="checked"/>
        <label for="first_radio_no">No</label>
    </fieldset>
</div>


<div id="second_radio_div" name="second_radio_div">
    <div data-role="fieldcontain">
        <fieldset data-role="controlgroup" data-type="horizontal">
            <div>Second Radio</div>
            <input type="radio" name="second_radio" id="second_radio_yes" value="yes" />
            <label for="second_radio_yes">Yes</label>

            <input type="radio" name="second_radio" id="second_radio_no" value="no" checked="checked"/>
            <label for="second_radio_no">No</label>
        </fieldset>
    </div>
</div>

<div id="third_element_div" name="third_element_div">
    <div data-role="fieldcontain">
        <input type="text" name="third_element" id="third_element" class="default-value" value="If yes, provide date" />                
    </div>
</div>

第一台收音机
对
不
第二台收音机
对
不
工作示例:


我认为你的主要问题是这句话:

$('input:radio[name="second_radio_no"]').attr('checked',true);
应该是:

$('#second_radio_no').attr('checked', true);
由于没有带有
[name=“second\u radio\u no”]

的元素,那么:

$("#second_radio_div").hide("fast");
$("#third_element_div").hide("fast");

$("[name='first_radio']").change(function() {
    $("#second_radio_div").toggle($("[name='first_radio']").index(this) === 0);

    if ($("[name='first_radio']").index(this) === 1) {
        $("#second_radio_no").attr("checked", true);
        $("#third_element_div").hide("fast"); // This works to hide the element
    }
});

$("[name='second_radio']").change(function() {
    $("#third_element_div").toggle($("[name='second_radio']").index(this) === 0);
});
在这里工作:


请注意(
[name='value']
)选择器中的“value”周围需要引号。

Hmm这是我已经做过的工作,我想向后工作,就像他们取消选择第二个单选选项(或选择否)以隐藏和清除第三个元素文本框中的值一样。如果他们在第一个单选框中取消选择(或选择否),我想在第三个元素文本框中隐藏并清除该值,在第二个单选框中选择否,并根据复选框的值而不是索引隐藏该值。我真的很喜欢这种方法,只是有一个奇怪的问题。选择选项yes(在alert()中)时,显示值no;选择no时,显示值yes。我在$(document).ready(function()中有一个表单,但我真的不认为这是问题所在。我也在使用jQueryMobile框架。关于为什么我得到以前的值而不是更改后的值,有什么想法吗?这个定义看起来很奇怪。你能发布到JSFIDLE吗?我根据你发布的内容重新编写了所有切换函数,因为我喜欢你使用的方法(非常感谢),这里是我在页面上运行的唯一其他JS:
$("#second_radio_div").hide("fast");
$("#third_element_div").hide("fast");

$("[name='first_radio']").change(function() {
    $("#second_radio_div").toggle($("[name='first_radio']").index(this) === 0);

    if ($("[name='first_radio']").index(this) === 1) {
        $("#second_radio_no").attr("checked", true);
        $("#third_element_div").hide("fast"); // This works to hide the element
    }
});

$("[name='second_radio']").change(function() {
    $("#third_element_div").toggle($("[name='second_radio']").index(this) === 0);
});