【发布时间】:2018-09-30 04:47:48
【问题描述】:
我正在制作一个 PHP Web 应用程序并将数据从 MySql 提取到下面的 HTML 表中。
<table id = "table" width="500px" cellpadding=2 celspacing=5 border=2 >
<tr>
<th>Subject Code</th>
<th>Subject Name</th>
<th>Question Paper</th>
</tr>
<?php while($row=mysqli_fetch_array($result)):?>
<tr>
<td align="center"><?php echo $row['Subject_Code'];?></td>
<td align="center"><?php echo $row['Subject_Name'];?></td>
<td align="center"><a href="javascript:showPaper()"><img border="0" alt="image" src="ProjectPictures/questionPaper.png" width="30" height="30"></a></td>
</tr>
<?php endwhile;?>
</table>
这是表格的输出
第三列由可点击的图像图标组成,可将试卷加载到除此之外的 iFrame 中。
我希望在单击此图像时,获得第一列的单元格值 --> 获得该特定行的“主题代码”。
代码如下:
function showPaper(){
var v;
//method1 not working
for(var i=1;i<table.rows.length; i++){
table.rows[i].onclick = function(){
rIndex = this.rowsIndex;
v=this.cells[0].innerHTML;
alert(v);
};
}
//method 2 not working
v = $("#table tr.selected td:first").html();
alert(v);
/*loc1 path rest of code
document.getElementById('myiFrame').src = loc1*/;
}
我需要将此主题代码值作为 iFrame 的 pdf src 路径中的变量之一。
但似乎没有任何效果,'v' 变量中的值显示为未定义。
我怎样才能使这段代码工作?
【问题讨论】:
-
将
Subject_Code直接传递给函数。然后你可以使用这个id在函数中做任何你想做的事情
标签: javascript php html html-table