【发布时间】:2019-03-25 16:07:36
【问题描述】:
我有一个默认隐藏的 div result_head。每当我单击将提供选项以选择结果的按钮时,此隐藏的 div 将显示为表单的标题。
<div class="result_head" id="result_head" style="display: none"> >Results</div>
以及表单代码
<form method="post" id="form_result">
<div class="form-group">
<-----some drop down menus here --------->
<div class="form-group">
<button type="submit" name="result_submit" id="result_submit" style="display: none;margin:1%;" >Submit</button>
</div>
</form>
提交后和页面刷新后,我需要显示结果的标题。 我尝试了不同的方法来实现,但没有任何运气。
尝试添加 onclick 和 onsubmit 函数以及表单提交
<button type="submit" name="result_submit" id="result_submit" style="display: none;margin:1%;" onclick="document.getElementById('result_head').style.display = 'block';">Submit</button>
尝试将 php 中的 CSS 回显到 display_head。
<div class="result_head" id="result_head" style="display: none" <?php if (isset($_POST['result_submit'])){ echo 'style="display:block !important;"'; } ?> >Results</div>
还发现了一个在表单提交后通过 php 回显整个 div 的方法,该方法将在表单提交后创建新的 div。但是这个选项对我来说是不可行的,因为我还需要在提交之前显示头部。
另外,在研究一些解决方案时,发现了一个将按钮类型从sumbit 更改为button 并使用jquery\ajax 提交表单的选项。我可能需要为此更改整个代码。
还有其他方法吗?
【问题讨论】:
-
HTML 标记中的 style 属性不能有两倍
标签: javascript php jquery html css