我有一个user question form,当我使用ajax提交表单并将其保存到数据库时,将显示一条成功消息,几秒钟后该消息将消失,并且user question form将自动再次显示。

我已经能够消失成功的消息,但是无法自动再次显示user question form

这是我的html标记:

<div class="so-widget-sow-editor so-widget-sow-editor-base question-modal">

    <div class="siteorigin-widget-tinymce textwidget">
        <h3>Ask Question</h3>
        <form>
            <div class="form-group">
                <input type="text" id="question_form_name" class="form-control" id="exampleInputPassword1" placeholder="Your name">
                <div id="question_form_name_error_message" class="val_error"></div>
            </div>

            <div class="form-group">
                <textarea class="form-control" id="question_form_text_area" rows="3" placeholder="Ask your question" style="height:10em;"></textarea>
                <div id="question_form_text_area_error_message" class="val_error"></div>
            </div>

            <button type="button" class="btn btn-primary" id="question_form_button">Submit</button>

        </form>
    </div>
</div>


这是我的Javascript代码:

$.ajax({

            url:"{{ url('/ask_question_form') }}",
            type: 'GET',
            data: {_token :token, name : name, email : email, contact : contact, question : question},
            success:function(msg){

                // console.log(msg);

                $('.question-modal .textwidget').hide();

                trHTML = "";
                trHTML += "<div id='user-question' style='margin-top:50%; color:#0071BC'>";

                trHTML += "Thanks for your question. We will save your question for further query and give a feedback as soon as possible.";


                trHTML += "</div>";

                $('.question-modal').append(trHTML);

                setTimeout(function() {
                    $('#user-question').hide();
                }, 10000);

                $('.question-modal .textwidget').css('display'​​​​​​​​​​​​​​​​​​​​​​​​​​​,'block');​​​​​​//----this part is not working
            }
        });

最佳答案

将显示代码再次放在setTimeout()内:

更改以下代码

setTimeout(function() {
    $('#user-question').hide();
}, 10000);

$('.question-modal .textwidget').css('display'​​​​​​​​​​​​​​​​​​​​​​​​​​​,'block');​​​​​​




setTimeout(function() {
    $('#user-question').hide();
    $('.question-modal .textwidget').show();​​​​​​
}, 10000);

关于javascript - 在javascript中隐藏另一个“div”后自动显示“div”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50782768/

10-16 19:26
查看更多