2 回答
TA贡献1995条经验 获得超2个赞
<?php
$count = 3;
for($i=0; $i<$count; $i++) {
?>
<table id ="gameweek_history<?php echo $i; ?>">
<script>function doCSV<?php echo $i; ?>() {
var table1 = document.getElementById("gameweek_history<?php echo $i; ?>").innerHTML;
<button onclick="doCSV(<?php echo $i; ?>)">Export HTML Table To CSV File</button>
</table>
<?php
}
?>
给出输出:
<table id ="gameweek_history0">
<script>function doCSV0() {
var table1 = document.getElementById("gameweek_history0").innerHTML;
<button onclick="doCSV(0)">Export HTML Table To CSV File</button>
</table>
<table id ="gameweek_history1">
<script>function doCSV1() {
var table1 = document.getElementById("gameweek_history1").innerHTML;
<button onclick="doCSV(1)">Export HTML Table To CSV File</button>
</table>
<table id ="gameweek_history2">
<script>function doCSV2() {
var table1 = document.getElementById("gameweek_history2").innerHTML;
<button onclick="doCSV(2)">Export HTML Table To CSV File</button>
</table>
TA贡献1829条经验 获得超6个赞
您应该从您的 javascript 中删除 PHP 代码。这样写:
<script>function doCSV(i) {
var table1 = document.getElementById("gameweek_history"+i).innerHTML;
// do something here with table1
</script>
<table id ="gameweek_history<? echo $i; ?>">
<button onclick="doCSV(<? echo $i; ?>)">Export HTML Table To CSV File</button>
- 2 回答
- 0 关注
- 134 浏览
添加回答
举报