【发布时间】:2021-11-30 15:02:44
【问题描述】:
我在 ajax 调用中创建动态发布数据,我也在其中创建复选框。但复选框不可点击。它显示在文档上,但单击时没有响应。没有显示勾选我的意思是用户点击的检查和未检查状态。除复选框外,一切正常。我还没有为复选框做任何 jquery。 在控制台中,我检查了复选框 html 和 id 值等正确显示 这是我的代码 //
if(mysqli_num_rows($result) > 0){
$output = "";
$output .= "<div class='col-12'><p id='content-title'>Fresh Posts</p></div>";
while($row = mysqli_fetch_assoc($result)) {
$title = substr($row['title'],0,25) . '...';
$description = substr($row['description'],0,200) . '...';
$output .= "<div class='col-4'>
<div class='post-content'>
<a href='single-post.php?id={$row['post_id']}' class='post-img'>
<img src='dashboard/uploads/{$row['post_img']}'>";
if(isset($_SESSION['logged-in'])){
$output .= "<input type='checkbox' id='{$row["post_id"]}' value='{$row['post_id']}' class='fav-icon-checkbox'>
<label for='{$row["post_id"]}'><i class='fa fa-heart fav-icon'></i></label>";
}
$output .= "</a>
<div class='post-info-container'>
<div class='post-info'>
<span class='post-author'><a href='#'>{$row['author']}</a></span>
<span class='dot'></span>
<span class='post-category'><a href='category.php?id={$row['category_id']}'>{$row['category_name']}</a></span>
<br>
<span class='post-date'>{$row['date']}</span>
</div>
<h5 class='post-title'>{$title}</h5>
<p class='post-description'>{$description}<a href='single-post.php?id={$row['post_id']}' class='read-more'>read more</a></p>
</div>
</div>
</div>";
}
echo $output;
}
【问题讨论】:
-
我会尝试删除
<input type='checkbox' ...上的课程。如果仍然无法点击,则尝试使用纯 HTML 手动添加复选框。如果仍然无法正常工作,请检查复选框上方是否有图层。 -
等等...你在复选框周围有一个锚点 (
<a ...)。只要您单击复选框,它就会将您发送到single-post.php。 -
您不能在 HTML 中嵌套“交互式”元素。不允许在链接中使用复选框。
标签: php jquery input checkbox dynamic