Js click overlay, global variable problem

problem description: enter "barcode" in the input box and click OK. If the barcode entered corresponds to the barcode in the form, the number of reviews in the tr will be increased by one. Why is the countPP I wrote correct the first time? if I enter the second "barcode" click OK, the number of checks will inherit the previous barcode superposition? Ask my brother for advice

var count = 0;
/ / enter
$(".conversation _ review") .click (function () {

$("tbody tr td:nth-child(3)").each(function(index,val){
  if($(this).html()==$(".nav-input").val()){
    console.log("-----------------------------");
    countPP;
    $(this).parent().children().eq(-2)[0].innerHTML= count;
  }
});

});

Feb.19,2022

the count you define is a global variable
initializes count=0
click and countPP becomes 1
Click count not 0 but 1
Let the current compound number of count= PP and innerHTML with each click



//enter
$('.confirm_review').click(function () {
    var count = 0;
    $('tbody tr td:nth-child(3)').each(function(index,val){
          if($(this).html()==$('.nav-input').val()){
                console.log('-----------------------------');
                count = 
                countPP;
                $(this).parent().children().eq(-2)[0].innerHTML= count;
          }
    });
});

is equivalent to sharing a count for every record you have

$('tbody tr td:nth-child(3)').each(function(index,val){
  if($(this).html()==$('.nav-input').val()){
    console.log('-----------------------------');
    // innerHTML
    // 
    var d = 
    $(this).parent().children().eq(-2)[0].innerHTML= dPP;
  }
});

also, it is recommended that you use an array to determine the corresponding records of your query, and then set the content according to the index value, which will be better


// 
var tabData = [{barCode:'', count:0},...];

// K - barCode
// V - tabRowData
var barCodeMapped = {};
for (var i in tabData) barCodeMapped[tabData[i].barCode] = tabData[i];

$('.confirm_review').click(function(){
    var 
        refer = $('.nav-input').val(),
        rowData = barCodeMapped[refer];
    
    // 
    if (rowData){
        // rowData.count
        rowData.count = (+rowData.count||0) + 1;
        var rowIndex = tabData.indexOf(rowData);
        $('tbody>tr:eq(' + rowIndex + ')>td:eq(-2)').html(rowData.count);
    }
});

rowData has many advantages in saving data:

  • to extract this set of data and send it to the server
  • sort by number of reviews
  • wait
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e449dd-650e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e449dd-650e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?