retain show / hide div on multistep form

╄→尐↘猪︶ㄣ 提交于 2019-12-25 03:24:37

问题


I have a multistep form and I'm showing / hiding divs based on a radio input selection. The code below works when you click the input you want, but if I move to the next page and then back again, it "remembers" which option was selected but hides both divs again. Any suggestions?

$(document).ready(function() {
  if($('form#enter-details-form').length) {
        $("div[id^='p_option_']").hide('fast');

        $("input[name='p_method']:checked").each(function() {
            $("#p_option_" + $(this).val()).show();
        });

        $("input[name='p_method']").click(function() {
            $("div[id^='p_option_']").hide();
        $("#p_option_" + $(this).val()).show();
        });
  }
});


<div class="form-radios">
    <label><input type="radio" class="form-radio" value="0" name="p_method" id="edit-p-method-0"> Option 1 </label>
    <label><input type="radio" class="form-radio" value="1" name="p_method" id="edit-p-method-1"> Option 2</label>
</div>

<div id="p_option_0">Show this for option 0</div>
<div id="p_option_1">Show this for option 1</div>

回答1:


Strangely enough removing the duration argument ('fast') from the initial .hide() seems to fix the problem.

Here is a working example: http://jsfiddle.net/qb2sk/



来源:https://stackoverflow.com/questions/6861981/retain-show-hide-div-on-multistep-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!