表单提交后显示隐藏的内容

时间:2017-01-19 03:13:49

标签: javascript jquery

我有一个表单,如果我在select标签中选择一个选项,则会显示一些内容。问题是如果我提交表单并且出现错误,则内容现在已隐藏。

我阅读了相关主题并说明了本地存储,但我不知道如何实现它。

这是我的示例脚本。感谢

SCRIPT

match_parent

1 个答案:

答案 0 :(得分:0)

您的脚本仅在值更改时运行,您可能还需要在页面加载时运行它。

// Make it a function
function updateVisibleServices(){
    if ( this.value == '11'){
        $("#services11").show();
        $("#services13").hide();
        $("#services14").hide();
    }
    else if ( this.value ==  '13') {
        $("#services13").show();
        $("#services11").hide();
        $("#services14").hide();
    }
    else if ( this.value ==  '14') {
        $("#services14").show();
        $("#services11").hide();
        $("#services13").hide();
    }
    else {
        $("#services11").hide();
        $("#services13").hide();
        $("#services14").hide();
    }
}

$(document).ready(function(){
    // Add the event
    $('#loc_type1').on('change', updateVisibleServices);
    // and also call it on page load
    updateVisibleServices();
});