gpt4 book ai didi

javascript - 如何为动态表创建弹出窗口

转载 作者:行者123 更新时间:2023-11-28 17:06:25 25 4
gpt4 key购买 nike

HTML

    function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
//-->
</script>


<!--To display JSON data in the tables-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script> $(function() {
var dmJSON = "data.json";
$.getJSON( dmJSON, function(data) {
$.each(data.records, function(i, f) {
var $table="<table class='mystyles' table border=5><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>&nbsp;&nbsp;&nbsp;</table>"
$("#entrydata").append($table)
});
});
});

<!--Popup function-->
$(function() {
$( "#dialog" ).dialog();
});

</script>

</head>
<body>
<div id="popup-box1" class="popup-position">
<div id="popup-wrapper">
<p style="text-align: right;"><a href="javascript:void(0)" onclick="toggle_visibility('popup-box1');">X</a></p>
<div id="popup-container">
<h3>Popup box 1</h3>
<p>A popup box</p>
</div><!-- Popup container end -->
<p style="text-align: right;"><a href="javascript:void(0)" >Close popup box</a></p>
</div><!-- Popup wrapper popup end -->
</div><!-- Popup box 1 end -->


<!--Creating a dynamic table-->
<a href="javascript:void(0)" onclick="toggle_visibility('popup-box1');">
<div class="wrapper" >
<div class="profile">
<div id='entrydata' >

</div>
</div>
</a>
</div>

代码动态创建表并显示 JSON 数据。我已经添加了一个弹出窗口,但问题是我需要为每个表使用不同的弹出窗口。例如:对于第一个表,我想要弹出窗口 1,第二个表应该显示弹出窗口 2。由于这些表是动态创建的,所以我不知道如何向其中添加不同的弹出窗口。对此的任何解决方案将不胜感激。提前致谢

最佳答案

您可以像这样为表分配唯一 ID。

<!--To display JSON data in the tables-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script> $(function() {
var dmJSON = "data.json";
$.getJSON( dmJSON, function(data) {
var idx=1;
$.each(data.records, function(i, f) {
var myid = 'mytable'+String(idx);
idx++;
var $table="<table id='"+myid+"' class='mystyles' table border=5><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>&nbsp;&nbsp;&nbsp;</table>"
$("#entrydata").append($table)
});

});
});

关于javascript - 如何为动态表创建弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30259066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com