我制作了一个网页,将图像上传到数据库n,然后从数据库中再次显示。。在上传图像时,我在文本区添加了评论,在再次显示评论时,评论也会显示出来,并且是可编辑的,现在我添加了一个添加评论的文本区,但没有显示,我想在点击带有jquery show功能的按钮时显示它
我可以在单击"添加评论"按钮时显示(使用jquery)文本区域(具有display:none属性),但问题是它总是打开最后上传的图像的文本区域
我读到使用jquery的最接近属性,但它对我的代码不起作用,我可能缺少一些我不知道的东西
这是我需要的css,如果你尝试运行程序,它需要。。
#commen{
display:none;
}
#sq {
background-image:url("wood.jpg");
margin-top:1%;
margin-left:30%;
margin-right:20%;
height: 70%;
width:40%;
float:left;}
上传时我显示图像和评论输入的代码,有一个添加按钮,可以提供
function displayimage()
{
<div id="sq">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "databaseimage";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = mysqli_query($conn,"SELECT * FROM images order by image_id DESC");
while ($image = mysqli_fetch_assoc($sql))
{
echo ' <img src="data:image/jpeg;base64,'.base64_encode( $image['url'] ).'" width="100%" height="100%">';
$id=$image['image_id'];
$sqlit = mysqli_query($conn,"SELECT * FROM images_comments where comment_id='$id'");
$image1 = mysqli_fetch_assoc($sqlit);
$text = $image1['text'];
echo "<form method='post' action='page.php'>
<textarea name='comment' onblur=style.backgroundColor='darkgray' onclick=style.backgroundColor='white'>$text</textarea>
<input type='hidden' name='imageID' value='$id'/>
<input type='submit' name='submitComment' value='Submit'></form>";
echo "<div id='commen'>
<form method='POST' action='comm.php'>
<textarea name='commentx'></textarea>
<input type='submit' name='Adcom' value='Add'>
</form>
</div><a class='comment'>Add Comment</a>";
echo nl2br("n");
}
?>
</div>
我的jquery函数
<script>
$(document).ready(function(e) {
$('.comment').click(function(){
$('#commen').show();
});
});
</script>
我只是不知道如何使用最接近函数
只需要知道如何在这里正确使用最接近的功能
感谢您的帮助,谢谢
我也尝试过这个代码来显示
$('.comment').click(function(){
$(this).prev().show();
});
首先,您可能不应该在同一页上有多个具有相同id
的元素。您可能想要在JavaScript中使用
$('.comment').click(function(){
$(this).prev().show();
});