我正在用新内容动态替换div内容。我的新内容是从数据库中获取的记录,该记录存储为变量数据中列表的列表。每次单击“提交”按钮时,内容应替换为列表中的下一项。我已经声明了一个全局变量I,以便从data []中获取相应的项,并且我正在尝试增加i。但是每次我被初始化为原始值。请帮忙。我已经在这里附加了代码。
<html>
<head>
{% set i=0%}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
function ReplaceContentInContainer(id, content) {
var container = document.getElementById(id);
container.innerHTML = "";
container.innerHTML = document.getElementById('blockOfStuff').innerHTML;
}
</script>
<script id="blockOfStuff" type="text/html">
<div id="d1">
{% set i=i+1%} {% for item in data[i]%}
<tr>
{{item}}
</tr>
<br> {% endfor %}
<input type="submit" onclick="javascript:ReplaceContentInContainer('d1','')">
</div>
</script>
</head>
<body>
<div id="d1">
{% for item in data %}
<tr>
{% for val in item %}
<td>{{val}}</td>
<br> {% endfor %}
</tr>
<br>
<input type="submit" onclick="javascript:ReplaceContentInContainer('d1','')"> {% break %} {% endfor %}
</div>
</body>
</html>