如何使用Jquery动态弹出数据

时间:2018-07-27 04:07:26

标签: javascript jquery html css twitter-bootstrap

在这种情况下,我试图在用户单击按钮时获取弹出式/模态表单。我从Link获取表单数据,但我不知道该如何处理。基本上我可以使用引导程序创建模态,但是问题是我无法将此Jquery与引导程序模态集成。那么如何解决这个问题。请帮助我,我被困住了。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
        crossorigin="anonymous">
</head>

<body>

    <div class="container">
        <button class="btn btn-primary btn-action" data-url="/echo?someval=mydatavalue1" id="btnAction1">Button API Call 1</button>
        <button class="btn btn-primary btn-action" data-url="/echo?someval=mydatavalue2" id="btnAction2">Button API Call 2</button>
        <div id="myModal" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Modal</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    </div>
                    <div class="modal-body">
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <h1>Getting started with JSON Form</h1>
    <form></form>
    <div id="res" class="alert"></div>


    <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em"
        crossorigin="anonymous"></script>
    <!-- <script type="text/javascript" src="deps/jquery.min.js"></script> -->
    <script type="text/javascript" src="deps/underscore.js"></script>
    <script type="text/javascript" src="deps/opt/jsv.js"></script>
    <script type="text/javascript" src="lib/jsonform.js"></script>

    <script type="text/javascript" >
    $(document).ready(function () {

    var test = function x() {
        $('form').jsonForm({
            schema: {
                name: {
                    type: 'string',
                    title: 'Name',
                    required: true
                },
                age: {
                    type: 'number',
                    title: 'Age'
                }
            },
            onSubmit: function (errors, values) {
                if (errors) {
                    $('#res').html('<p>I beg your pardon?</p>');
                } else {
                    $('#res').html('<p>Hello ' + values.name + '.' +
                        (values.age ? '<br/>You are ' + values.age + '.' : '') +
                        '</p>');
                }
            }
        });
    }

    $('.btn-action').click(function () {
        // update modal content
        $('.modal-body').html(test())
        // // show modal
        $('#myModal').modal('show');
    });
});
    
    </script>

</body>

</html>

最后,我想要的是当我单击按钮时,应该使用上面的Form数据打开模态。我不知道天气如何,要正确解决这个问题,或者不建议我提出任何其他解决方案,这是我的初学者,这是我在工作中的工作。

1 个答案:

答案 0 :(得分:1)

$未定义意味着找不到jquery库,请检查依赖项,JSON Form库取决于jQuery,尝试添加jQuery库