【问题标题】:Dynamically created checkbox not clickable动态创建的复选框不可点击
【发布时间】: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;
}

【问题讨论】:

  • 我会尝试删除&lt;input type='checkbox' ... 上的课程。如果仍然无法点击,则尝试使用纯 HTML 手动添加复选框。如果仍然无法正常工作,请检查复选框上方是否有图层。
  • 等等...你在复选框周围有一个锚点 (&lt;a ...)。只要您单击复选框,它就会将您发送到single-post.php
  • 您不能在 HTML 中嵌套“交互式”元素。不允许在链接中使用复选框。

标签: php jquery input checkbox dynamic


【解决方案1】:

检查复选框的值属性尝试更改单引号 :: $row["post_id"]。

【讨论】:

  • 我做了但没有工作,如果标签不工作,至少复选框应该工作
  • 我在控制台中检查了属性 id 值.. 非常好
  • 尝试将 id 名称更改为附加您的 post_id 的字符串 :: "somename{$post_id}"
猜你喜欢
  • 2019-12-14
  • 2018-05-17
  • 1970-01-01
  • 2011-04-18
  • 2013-01-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多