【问题标题】:maintain the state of a radio-toggled div after page reload页面重新加载后保持单选切换 div 的状态
【发布时间】:2012-02-18 18:28:14
【问题描述】:

In my form there are some radio buttons - when the radio is selected - the div appears, when another one is selected - the div hides.如果有一些错误,提交表单后,页面重新加载并且 div 应该仍然显示(如果选择了收音机)。以下解决方案仅适用于复选框 - 如何使其适用于收音机?
https://stackoverflow.com/a/8406409/1137417
这是我的代码:

    $(function(){

    $('#Q07_03, #Q07_07, #Q08_03').hide();

    // checkboxes
    $('#Q07_03').toggle($('#Q07_02').is(':checked'));
    $('#Q07_02').click(function() {
    $('#Q07_03').toggle(); });

    $('#Q07_07').toggle($('#Q07_06').is(':checked'));
    $('#Q07_06').click(function() {
    $('#Q07_07').toggle(); });

    // here code for radio ?
    // #Q08_03 is the div to be displayed;
    // #Q08_02 is the one that should be selected
    })

【问题讨论】:

    标签: jquery html toggle reload radio


    【解决方案1】:

    为什么不使用 ajax 提交表单呢?你不会遇到这类问题。好回答你的问题,你可以试试这个。

    //I don't know how many radio buttons are there on the page and what there names are
    //you can accordingly change the radio button selector to check if it is checked or not
    
    $(document).ready(function() {
         if($("input:radio:first").is(":checked"))
             $('divToShowHide').show()
         else
             $('divToShowHide').hide()
    });
    

    【讨论】:

    • 我已经更新了我的帖子,以便您可以看到代码。您的解决方案似乎不起作用...我现在不太了解 ajax,但感谢您的建议
    • 必须有一些简单的解决方案...?
    猜你喜欢
    • 1970-01-01
    • 2013-11-09
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2016-08-23
    • 2015-10-18
    • 1970-01-01
    相关资源
    最近更新 更多