如何在表单中点击提交按钮后显示隐藏的div? [英] How to show hidden div after hitting submit button in form?

查看:143
本文介绍了如何在表单中点击提交按钮后显示隐藏的div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的HTML表单和提交按钮。点击此按钮后,我想看看之前看不到的 div#my_id

I have simple HTML form with submit button. After hitting this button I would like to the see div#my_id which is not visible before.

<input type="submit" name="xxx" value="yyy" onclick="document.getElementById('my_id').style.display = 'block' ;">

<div id="my_id" style="display: none"> My text </div>

我如何才能使它工作?

推荐答案

您的HTML是否包含在< form> 标记内?您的提交按钮可能是在提交表单并在执行JavaScript之前导致页面刷新。

Is your HTML contained within the <form> tag? It is likely that your submit button is submitting the form and causing a page refresh before the JavaScript is executed.

如果是这种情况,请尝试将输入类型更改为按钮看到效果。

If this is the case, try changing the input type to button to see the effect.

例如:

#my_id {
    display: none;
}

<form>
    <input type="button" name="xxx" value=" Show Text! " onclick="document.getElementById('my_id').style.display = 'block' ;" />
    <div id="my_id"> My text </div>
 </form>

这篇关于如何在表单中点击提交按钮后显示隐藏的div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆