Javascript 如何在文本等于某个内容后隐藏或禁用按钮
如果text id=“Status”==YES,如何禁用或隐藏按钮id=“edit_button”Javascript 如何在文本等于某个内容后隐藏或禁用按钮,javascript,php,Javascript,Php,如果text id=“Status”==YES,如何禁用或隐藏按钮id=“edit_button” 我试着用谷歌搜索,但这里唯一能做的是,只有第一行隐藏了表中的按钮。您遇到的问题是,您没有将该部分分解,因此可以使用if语句。其次,作为一个方面,您需要参数化sql。第三,您有一些无效的html,最后,正如注释中所指出的,您应该有唯一的ID。如果您有缩进,也会很有帮助: <?php $query = "SELECT * from complaintbl where userna
我试着用谷歌搜索,但这里唯一能做的是,只有第一行隐藏了表中的按钮。您遇到的问题是,您没有将该部分分解,因此可以使用
if
语句。其次,作为一个方面,您需要参数化sql。第三,您有一些无效的html,最后,正如注释中所指出的,您应该有唯一的ID。如果您有缩进,也会很有帮助:
<?php
$query = "SELECT * from complaintbl where username =
'{$_SESSION['username']}'";
$result = mysqli_query($con,$query);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>".$row['complain_title']."</td>";
echo "<td>".$row['complain_text']."</td>";
echo "<td><input type=\"text\" id=\"Status\" class=\"form-control editField\" style=\"width:50px;\" name=\"Status\" value=\"".$row['Status']."\" readonly/></td>";
echo '<td><a href="studenteditcomplain.php?cid='.$row['cid'].'"><button title="edit" id="edit_button" type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil white"></span></button></a><a href="deletecomplain.php?cid=' . $row["cid"].';><button title="delete" type="button" class="btn btn-default btn-sr" data-confirm="Are you sure to delete this item?"><span class="glyphicon glyphicon-trash white"></span></button></a></td>';
}
}
else
{
echo "</table>";
echo '<p class="a1"><b>You have no item. Please insert item</p>';
}
?>
你不想给每个文本框和每个按钮都赋予相同的ID。在ID中添加某种迭代器。所以我应该使用类?你能提供一个javascript例子吗?.旁注:你知道现在用什么来查询数据库是危险的吗?你不知道准备好的语句,或者你不在乎你是否在线使用它,然后你发现你的数据库有一天会被删除?只需将ID设置为类似“编辑按钮”的内容即可$行['cid'],所以它们都是不同的。
<table>
<?php
# You should switch to the OOP version of mysqli, it is more straight-forward when it comes to binding and overall use, in my opinion
# It would be better to create a function and include it than do this type of syntax here. It's not wrong necessarily, it's just messy and harder to read
$sql = "SELECT * from complaintbl where username = ?";
$query = $con->prepare($sql);
$query->bind_param('s', $_SESSION['username']);
$query->execute();
if($result->num_rows > 0):
while($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['complain_title'] ?></td>
<td><?php echo $row['complain_text'] ?></td>
<td><input type="text" class="status form-control editField" style="width:50px;" name="Status" value="<?php echo $row['Status'] ?>" <?php if($row['Status'] == 'YES') echo 'readonly' ?> /></td>
<td><a href="studenteditcomplain.php?cid=<?php echo $row['cid'] ?>"><button title="edit" type="button" class="edit_button btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil white"></span></button></a><a href="deletecomplain.php?cid=<?php echo $row["cid"] ?>"><button title="delete" type="button" class="btn btn-default btn-sr" data-confirm="Are you sure to delete this item?"><span class="glyphicon glyphicon-trash white"></span></button></a></td>
<!-- You need to end the row -->
</tr>
<?php endwhile ?>
<?php else: ?>
<!-- you should close the <b> tag -->
<p class="a1"><b>You have no item. Please insert item</b></p>
<?php endif ?>
<!-- Seems like you should end the table regardless if there are no rows -->
</table>