【发布时间】:2014-03-06 12:54:40
【问题描述】:
首先我想说这个问题与jquery replacewith to get data with Ajax after click on a cell有关,如果这违反规则我很抱歉并删除此帖子。
我试图在 MySQL 生成的表中获取单元格的值(使用 fetch_array)。我想单击同一单元格并接收 div 容器中行中第一个单元格的值。
感谢这里的几个条目,我找到了“静态”表的示例。像这样:
<table id="choose-address-table" class="ui-widget ui-widget-content">
<thead>
<tr class="ui-widget-header ">
<th>Name/Nr.</th>
<th>Street</th>
<th>Town</th>
<th>Postcode</th>
<th>Country</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<tr>
<td class="nr"><span>50</span>
</td>
<td>Some Street 1</td>
<td>Glasgow</td>
<td>G0 0XX</td>
<td>United Kingdom</td>
<td class="use-address">
Use
</td>
</tr>
<tr>
<td id="chip" class="nr">49</td>
<td>Some Street 2</td>
<td>Glasgow</td>
<td>G0 0XX</td>
<td>United Kingdom</td>
<td>
<button type="button" class="use-address">Use</button>
</td>
</tr>
</tbody>
</table>
<br><br>
<div id="glasgow">Hello</div>
和
$("#chip").click(function () {
var scotland = $(this).closest("tr").find(".nr").text();
$("#glasgow").html(scotland);
});
http://jsfiddle.net/FnDvL/231/
工作正常。我将它插入到我的文件 php 中,并从 mysql 获取表数据。
这是我的代码:
<html>
<head>
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(".information").click(function () {
var rodney = $(this).closest("tr").find(".nr").text();
$(".clicked_info").html(rodney);
});
</script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<?
$con = mysqli_connect('localhost','root','','boerse');
$sql="SELECT short, name FROM markets";
$result = mysqli_query($con,$sql);
?>
<div class="markets">
<?
echo "<table>
<thead border='0'>
<tr>
<th>Index</th>
<th>Name</th>
</tr>
</thead>
<tbody border='1'>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td class='nr'>" . $row['short'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td class='information'>Use</td>";
echo "</tr>";
}
echo "</tbody></table>";
?>
<div class="clicked_info">Hello</div>
</div>
<br><br>
</body>
</html>
现在我的问题是我可以点击带有类信息的 td,但 div class 'clicked_info' 没有改变。但我确实喜欢小提琴。那么出了什么问题呢?或者问题出在哪里?它必须与 MySQL 问题有关。但为什么呢?
这样我想检查我是否从单元格中获取了内容,并且我可以继续使用它(如我之前的帖子中所见)。
也许任何人都可以提供帮助。如果我在这里违反规则,我再次感到抱歉。
谢谢大家。
【问题讨论】:
-
将您的事件处理程序
$(".information").click(function () {.....包装在文档就绪处理程序中
标签: php jquery mysql datatable