gpt4 book ai didi

javascript - 在javascript中隐藏另一个 'div'后自动显示 'div'

转载 作者:行者123 更新时间:2023-12-03 01:42:18 25 4
gpt4 key购买 nike

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

我能够消失成功消息,但无法自动再次显示用户问题表单

这是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com