jquery - 单击按钮时弹出一个表单

标签 jquery html forms popup

我希望在单击按钮时在页面中央显示一个表单。我在 http://jqueryui.com/dialog/#modal-form 找到了解决方案. 但是可以不用包含 jqueryui 以更简单的方式完成吗?

此外,如何使背景字段不可访问?即,当表单打开时,背景字段应该是可见的,但我不应该能够与它们互动。

最佳答案

创建一个隐藏表单,然后单击按钮使用 .show() 切换表单和 .hide()

$('#show').on('click', function () {
    $('.center').show();
    $(this).hide();
})

$('#close').on('click', function () {
    $('.center').hide();
    $('#show').show();
})
.center {
    margin: auto;
    width: 60%;
    padding: 20px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.hideform {
    display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="center hideform">
    <button id="close" style="float: right;">X</button>
    <form action="/action_page.php">
        First name:<br>
        <input type="text" name="firstname" value="Mickey">
        <br>
        Last name:<br>
        <input type="text" name="lastname" value="Mouse">
        <br><br>
        <input type="submit" value="Submit">
    </form>
</div>
<button id="show">Show form</button>

关于jquery - 单击按钮时弹出一个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44091397/

相关文章:

javascript - 在 Javascript/Ajax 而不是 PHP 中验证表单的安全方法?

html - 为什么我的 html 表单的密码输入字段有浅蓝色背景?

javascript - 如何按相邻元素对元素集合进行分组?

javascript - Tinymce 内联编辑器不会在 Bootstrap 模式中显示菜单或工具栏

javascript - 变量不改变 Javascript

Javascript 价格计算器问题(复选框)

javascript - 从 JQuery 中的多个表单中选择表单

javascript - JQuery 检测空 p 标签

jquery - 如何在悬停在 div 上时显示叠加文本并在 html 和 css 中隐藏 div 上的当前文本

javascript - 在调用验证之前给 Formik 初始错误值