【问题标题】:Click in checkbox gives me undefined单击复选框给我未定义
【发布时间】:2022-01-09 00:55:48
【问题描述】:

我是 php 新手,我的复选框有问题。事实上,当我选中表中的一个复选框时,它应该给我我的数据,但不幸的是它给了我未定义的数据。

这是我点击复选框之前的代码 enter image description here

在第一行的复选框中单击示例后 enter image description here

这是我的代码:

$(document).on('click', '.check_box', function(){
    var html = '';
    if(this.checked)
    {
        html = '<td><input type="checkbox" id="'+$(this).attr('id')+'" data-Projet="'+$(this).data('Libelle_Projet')+'" data-Num-Produit="'+$(this).data('Num_Produit')+'" data-Libelle-Produit="'+$(this).data('Libelle_Produit')+'" data-Titre-Foncier-Produit="'+$(this).data('Titre_Foncier_Produit')+'" data-Superficie-Produit="'+$(this).data('Superficie_Produit')+'" data-Date-Reception-Administratif-Temp="'+$(this).data('Date_Reception_Administratif_Temp')+'" data-Date-Contrat-Temp="'+$(this).data('Date_Contrat_Temp')+'" class="check_box" checked /></td>';
        html += '<td>'+$(this).data("Libelle_Projet")+'</td>';
        html += '<td>'+$(this).data("Num_Produit")+'</td>';
        html += '<td>'+$(this).data("Libelle_Produit")+'</td>';
        html += '<td>'+$(this).data("Titre_Foncier_Produit")+'</td>';
        html += '<td>'+$(this).data("Superficie_Produit")+'</td>';
        html += '<td><input type="date" name="Date_Reception_Administratif_Temp[]" class="form-control" value="'+$(this).data("Date_Reception_Administratif_Temp")+'" /></td>';
        html += '<td><input type="date" name="Date_Contrat_Temp[]" class="form-control" value="'+$(this).data("Date_Contrat_Temp")+'" /><input type="hidden" name="hidden_id[]" value="'+$(this).attr('id')+'" /></td>';
    }
    else
    {
        html = '<td><input type="checkbox" id="'+$(this).attr('id')+'" data-Projet="'+$(this).data('Libelle_Projet')+'" data-Num-Produit="'+$(this).data('Num_Produit')+'" data-Libelle-Produit="'+$(this).data('Libelle_Produit')+'" data-Titre-Foncier-Produit="'+$(this).data('Titre_Foncier_Produit')+'" data-Superficie-Produit="'+$(this).data('Superficie_Produit')+'" data-Date-Reception-Administratif-Temp="'+$(this).data('Date_Reception_Administratif_Temp')+'" data-Date-Contrat-Temp="'+$(this).data('Date_Contrat_Temp')+'" class="check_box" /></td>';
        html += '<td>'+$(this).data('Libelle_Projet')+'</td>';
        html += '<td>'+$(this).data('Num_Produit')+'</td>';
        html += '<td>'+$(this).data('Libelle_Produit')+'</td>';
        html += '<td>'+$(this).data('Titre_Foncier_Produit')+'</td>';
        html += '<td>'+$(this).data('Superficie_Produit')+'</td>';
        html += '<td>'+$(this).data('Date_Reception_Administratif_Temp')+'</td>';    
        html += '<td>'+$(this).data('Date_Contrat_Temp')+'</td>';         
    }
    $(this).closest('tr').html(html);
});

我的表代码:

<form method="post" id="update_form">
        <div id="divShow" class="table-responsive">
          <table class="table table-bordered table-striped">
            <thead>
              <th width="2%"></th>
              <th width="15%">Projet</th>
              <th width="10%">Numéro Produit</th>
              <th width="15%">Dénomination</th>
              <th width="10%">Titre Foncier</th>
              <th width="5%">Superficie</th>
              <th width="15%">Date Réception Admin</th>
              <th width="15%">Date Contrat</th>
            </thead>
            <tbody></tbody>
          </table>
        </div>
        
        <br />

        <div align="left">
          <input type="submit" name="multiple_update" id="multiple_update" class="btn btn-info" value="Valider"  style="display: none;" />
        </div>

        <br />

        <div id="msgSelectProduit" style="display: none;"></div>
        <div id="msgSelectDateContrat" style="display: none;"></div>
      </form>

$.ajax({
        url:"selectTOUT.php",
        method:"POST",
        dataType:"json",
        success:function(data)
        {
            var html = '';
            for(var count = 0; count < data.length; count++)
            {
                html += '<tr>';
                html += '<td><input type="checkbox" id="'+data[count].id+'" data-Projet="'+data[count].Libelle_Projet+'" data-Num-Produit="'+data[count].Num_Produit+'" data-Libelle-Produit="'+data[count].Libelle_Produit+'" data-Titre-Foncier-Produit="'+data[count].Titre_Foncier_Produit+'" data-Superficie-Produit="'+data[count].Superficie_Produit+'" data-Date-Reception-Administratif-Temp="'+data[count].Date_Reception_Administratif_Temp+'" data-Date-Contrat-Temp="'+data[count].Date_Contrat_Temp+'" class="check_box"/></td>';
                html += '<td>'+data[count].Libelle_Projet+'</td>';
                html += '<td>'+data[count].Num_Produit+'</td>';
                html += '<td>'+data[count].Libelle_Produit+'</td>';
                html += '<td>'+data[count].Titre_Foncier_Produit+'</td>';
                html += '<td>'+data[count].Superficie_Produit+'</td>';
                html += '<td>'+data[count].Date_Reception_Administratif_Temp+'</td>';
                html += '<td>'+data[count].Date_Contrat_Temp+'</td></tr>';
            }
            $('tbody').html(html);
        }
    });

【问题讨论】:

  • 可以给我复选框的html代码
  • 您是否可以发布降价(HTML)代码。关于整个这件事,有些东西有点不对劲。您正在收听课程 .check_box - 但随后您将获得 id ($(this).attr('id') from 点击的对象 。但那是复选框(而不是行)。所以要么你HTML 写得很奇怪 - 或者这可能是解释,为什么它不起作用。
  • @mahmoudmagdy 是的,我肯定会在帖子中添加它并提前感谢您
  • @Zeth 谢谢你的帮助是的,我不知道问题出在哪里我按照教程但是它对我不起作用我在帖子中添加了我的表格代码
  • 你的数据表 html 代码在哪里?

标签: javascript php mysql checkbox datatable


【解决方案1】:

尝试将一些破折号转换为下划线 就像那个 data-aa-b 到 data-aa_b

我认为这是问题

【讨论】:

  • 尝试在数据后面直接打破折号,其他变成下划线
  • 非常感谢先生,是的,问题出在破折号上
猜你喜欢
  • 2019-02-24
  • 1970-01-01
  • 2010-10-28
  • 2020-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-21
相关资源
最近更新 更多