Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何向动态创建的表添加弹出窗口/模式_Javascript_Jquery_Html_Css_Json - Fatal编程技术网

Javascript 如何向动态创建的表添加弹出窗口/模式

Javascript 如何向动态创建的表添加弹出窗口/模式,javascript,jquery,html,css,json,Javascript,Jquery,Html,Css,Json,HTML Javascript 上面的代码动态创建表并显示我的JSON文件中的数据。我想将这些表设置为按钮,并将弹出窗口添加到这些表中,这样当单击一个表时,就会出现一个弹出窗口,每个弹出窗口都应该有不同的数据。这方面的任何解决方案都会有所帮助。提前感谢。主要技巧是将单击处理程序绑定到文档: $(document).on("click", ".buttonInTd", function() { /* give your buttons the 'buttonInTd' class and

HTML

Javascript


上面的代码动态创建表并显示我的JSON文件中的数据。我想将这些表设置为按钮,并将弹出窗口添加到这些表中,这样当单击一个表时,就会出现一个弹出窗口,每个弹出窗口都应该有不同的数据。这方面的任何解决方案都会有所帮助。提前感谢。

主要技巧是将单击处理程序绑定到文档:

$(document).on("click", ".buttonInTd", function() {
    /* give your buttons the 'buttonInTd' class and add your onclick code here */
});
这样做将允许您动态创建一个表,并且仍然可以捕获它的事件

要处理modals和弹出窗口,我建议您只需从众多插件中选择一个即可。我真的很喜欢HTML:

<html>

    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">

        </script>
        <script>
            $(document).ready(function() {
                $(function() {
                    var dmJSON = "data.json";
                    $.getJSON(dmJSON, function(data) {
                        var $count = 0;
                        $.each(data.records, function(i, f) {
                            var $table = "<button type='button' class='show_btn'>show table" + ++$count + "</button><br><table border=1 class='table_hide'><tbody><tr>" + "<td>" + f.Clue + "</td></tr>" + "<tr><td>" + f.Answer + "</td></tr>" + "<tr><td>" + f.Status + "</td></tr>" + "<tr><td> " + f.Views + "</td></tr>" + "</tbody></table>"
                            $("#entrydata").append($table)
                        });
                        $(".show_btn").click(function() {
                            $(this).next().next().show()
                            $(this).hide();
                        });
                    });
                });
            });
        </script>
        <style>
            .table_hide {
                display :none;
            }
        </style>
    </head>

    <body>
        <div class="wrapper">
            <div class="profile">
                <div id='entrydata'></div>
            </div>
        </div>
    </body>

</html>

至少让我们看看你在HTML中尝试了什么,除了丑陋的警报之外,没有模式弹出窗口。您可以在顶部显示灰色、半透明、全宽和全高的图像,以灰显现有内容,并在其顶部显示一个div以显示弹出内容。我打赌会有lotsa Jquery模块用于此目的。您是否要求在单击时调用另一个ajax并在弹出窗口中将日期显示为表?否。我的表已经有预定义的数据。在弹出窗口中,我想详细描述我的表数据。您解决了问题吗?我的错误是,您在添加到DOM后正在绑定。
$(document).on("click", ".buttonInTd", function() {
    /* give your buttons the 'buttonInTd' class and add your onclick code here */
});
<html>

    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">

        </script>
        <script>
            $(document).ready(function() {
                $(function() {
                    var dmJSON = "data.json";
                    $.getJSON(dmJSON, function(data) {
                        var $count = 0;
                        $.each(data.records, function(i, f) {
                            var $table = "<button type='button' class='show_btn'>show table" + ++$count + "</button><br><table border=1 class='table_hide'><tbody><tr>" + "<td>" + f.Clue + "</td></tr>" + "<tr><td>" + f.Answer + "</td></tr>" + "<tr><td>" + f.Status + "</td></tr>" + "<tr><td> " + f.Views + "</td></tr>" + "</tbody></table>"
                            $("#entrydata").append($table)
                        });
                        $(".show_btn").click(function() {
                            $(this).next().next().show()
                            $(this).hide();
                        });
                    });
                });
            });
        </script>
        <style>
            .table_hide {
                display :none;
            }
        </style>
    </head>

    <body>
        <div class="wrapper">
            <div class="profile">
                <div id='entrydata'></div>
            </div>
        </div>
    </body>

</html>