Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.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 无法根据jQuery中的单选按钮选择隐藏或显示div_Javascript_Jquery_Html - Fatal编程技术网

Javascript 无法根据jQuery中的单选按钮选择隐藏或显示div

Javascript 无法根据jQuery中的单选按钮选择隐藏或显示div,javascript,jquery,html,Javascript,Jquery,Html,我正在处理一个需求,在这个需求中,我根据单选按钮选择显示字段。 以下是守则- $( document ).ready(function() { $('#selection_0').select(function () { $('#text_to_speech').show(); $('#recorded_messages').hide(); $('#recorded_messages').fi

我正在处理一个需求,在这个需求中,我根据单选按钮选择显示字段。 以下是守则-

        $( document ).ready(function() {
        $('#selection_0').select(function () {
            $('#text_to_speech').show();
            $('#recorded_messages').hide();
            $('#recorded_messages').find('input, textarea, button, select').each(function () {
                $(this).prop('disabled', true)});
            $('#text_to_speech').find('input, textarea, button, select').each(function () {
                $(this).prop('disabled', false)});


        });

        $('#selection_1').select(function () {
            $('#recorded_messages').show();
            $('#text_to_speech').hide();
            $('#recorded_messages').find('input, textarea, button, select').each(function () {
                $(this).prop('disabled', false)});
            $('#text_to_speech').find('input, textarea, button, select').each(function () {
                $(this).prop('disabled', true)});

        });
    });
我无法使此代码正常工作。控制台中也没有错误。 试试这个:

$("input[name=someRadioGroup]:radio").change(function () {
//Your code
});
试试下面

$( document ).ready(function() {
            $('#selection_0').click(function () {
                alert(4)
                $('#text_to_speech').show();
                $('#recorded_messages').hide();
                $('#recorded_messages').find('input, textarea, button, select').each(function () {
                    $(this).prop('disabled', true)});
                $('#text_to_speech').find('input, textarea, button, select').each(function () {
                    $(this).prop('disabled', false)});


            });

            $('#selection_1').click(function () {
                alert(7)
                $('#recorded_messages').show();
                $('#text_to_speech').hide();
                $('#recorded_messages').find('input, textarea, button, select').each(function () {
                    $(this).prop('disabled', false)});
                $('#text_to_speech').find('input, textarea, button, select').each(function () {
                    $(this).prop('disabled', true)});

            });
        });

使用
。更改
事件而不是
。选择

请参见演示

这应该对你有用

$("#selection :input[name=selection]").change(function () {
    var radioId = $(this).attr("id");
    if(radioId=='selection_0'){
    }
    else{
    }
});

选择在这里不起作用。使用更改或单击事件

              $( document ).ready(function() {
                    $('#selection_0').click(function () {
                        if ($('#selection_0').is(':checked')) {
                            $('#text_to_speech').show();
                            $('#recorded_messages').hide();
                            $('#recorded_messages').find('input, textarea, button, select').each(function () {
                                $(this).prop('disabled', true)});
                            $('#text_to_speech').find('input, textarea, button, select').each(function () {
                                $(this).prop('disabled', false)});
                        }

                });

                    $('#selection_1').click(function () {
                        if ($('#selection_1').is(':checked')) {
                            $('#recorded_messages').show();
                            $('#text_to_speech').hide();
                            $('#recorded_messages').find('input, textarea, button, select').each(function () {
                                $(this).prop('disabled', false)
                            });
                            $('#text_to_speech').find('input, textarea, button, select').each(function () {
                                $(this).prop('disabled', true)
                            });
                        }
                });
                });

尝试以下JQuery代码

$(文档).ready(函数(){


请注意,div的录制的消息文本到语音具有相同的html,因此可能看起来好像没有发生任何变化

我猜不是单选按钮!而且fiddle没有包含jQuery库!您可以像此fiddle一样单击使用,并且您的fiddle没有jQueryadded@user3004356
$("input[name='selection']").on('change', function () {

    if ($("input[name='selection']:checked").val() == 0) {           
        $('#text_to_speech').show();
        $('#recorded_messages').hide();
        $('#recorded_messages').find('input, textarea, button, select').each(function () {
            $(this).prop('disabled', true)});
        $('#text_to_speech').find('input, textarea, button, select').each(function () {
            $(this).prop('disabled', false)});
     }else{
        $('#recorded_messages').show();
        $('#text_to_speech').hide();
        $('#recorded_messages').find('input, textarea, button, select').each(function () {
            $(this).prop('disabled', false)});
        $('#text_to_speech').find('input, textarea, button, select').each(function () {
            $(this).prop('disabled', true)});

    }});
});