php中转义的问题。
<spanid=\"xiugaibtn\"onClick=\"xiugai($row[\'id\'])\">修改</span>这句加了$row[\'id\']报错。我想输...
<span id=\"xiugaibtn\" onClick=\"xiugai($row[\'id\'])\">修改</span>
这句加了$row[\'id\']报错。
我想输出onClick是事件中传值$row['id'],应该怎么写?
<?php
header("Content-Type: text/html; charset=utf-8");
$link = mysqli_connect("127.0.0.1", "root", "root", "test");
if (!$link){
echo"<script>alert('数据库连接失败!')</script>";
}
$link->query("SET NAMES UTF8");
$query = "select * from tt";
$result = mysqli_query($link, $query);
echo "<table border='2'>
<tr>
<th>id</th>
<th>nu</th>
<th>tel</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['un'] . "</td>";
echo "<td>" . $row['tel'] . "<span id=\"xiugaibtn\" onClick=\"xiugai($row[\'id\'])\">修改</span></td>";
echo "</tr>";
}
echo "</table>";
?> 展开
这句加了$row[\'id\']报错。
我想输出onClick是事件中传值$row['id'],应该怎么写?
<?php
header("Content-Type: text/html; charset=utf-8");
$link = mysqli_connect("127.0.0.1", "root", "root", "test");
if (!$link){
echo"<script>alert('数据库连接失败!')</script>";
}
$link->query("SET NAMES UTF8");
$query = "select * from tt";
$result = mysqli_query($link, $query);
echo "<table border='2'>
<tr>
<th>id</th>
<th>nu</th>
<th>tel</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['un'] . "</td>";
echo "<td>" . $row['tel'] . "<span id=\"xiugaibtn\" onClick=\"xiugai($row[\'id\'])\">修改</span></td>";
echo "</tr>";
}
echo "</table>";
?> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询