从表格内部的html中调用javascript的post变量为php。

问题描述 投票:0回答:2

第一种是有效的,第二种是无效的。唯一的区别是bekod发布的值。

当然在第一个脚本提醒中,我看到。10476062.

但是,这个:是好的,能用,我把记录找回来了,我怎么做错了?

版本1

var table = document.getElementById("progtable1");
if (table != null) {
  for (var i = 0; i < table.rows.length; i++) {
    for (var j = 0; j < table.rows[i].cells.length; j++)
      table.rows[i].cells[j].onclick = function() {
        var ii = this.parentNode.rowIndex;
        var value1 = table.rows[ii].cells[1].innerHTML;
        alert(value1);
        $.ajax({
          type: 'POST',
          url: 'recepciole.php',
          data: {
            lektip: "MU",
            bekod: value1
          },
          cache: false,
          success: function(result) {
            var osszhossz = result.length;
            var t = result.split("qncogi56");
            var rekordszam = t.length - 1;
            if (rekordszam == 1) {
              var k = t[i].split("|");
              var k = t[i].split("|");
              alert(k[5]);
              document.getElementById("alkalmaserveny_kiir").value = k[5];
            } else {
              alert("It has no record yet");
              return;
            }
          },
        })
      };
  }
}

版本2

var table = document.getElementById("progtable1");
if (table != null) {
  for (var i = 0; i < table.rows.length; i++) {
    for (var j = 0; j < table.rows[i].cells.length; j++)
      table.rows[i].cells[j].onclick = function() {
        var ii = this.parentNode.rowIndex;
        var value1 = table.rows[ii].cells[1].innerHTML;
        alert(value1);
        $.ajax({
          type: 'POST',
          url: 'recepciole.php',
          data: {
            lektip: "MU",
            bekod: "10476062"
          },
          cache: false,
          success: function(result) {
            var osszhossz = result.length;
            var t = result.split("qncogi56");
            var rekordszam = t.length - 1;
            if (rekordszam == 1) {
              var k = t[i].split("|");
              var k = t[i].split("|");
              alert(k[5]);
              document.getElementById("alkalmaserveny_kiir").value = k[5];
            } else {
              alert("It has no record yet");
              return;
            }
          },
        })
      };
  }
}
javascript html variables
2个回答
0
投票

这可以大大简化

$("#progtable1").on("click", "td", function() {
  const cellValue = $(this).closest("tr").find("td").eq(1).text().trim();
  console.log(cellValue);
  $.ajax({
    type: 'POST',
    url: 'recepciole.php',
    data: {
      lektip: "MU",
      bekod: cellValue
    },
    cache: false,
    success: function(result) {
      var osszhossz = result.length;
      var t = result.split("qncogi56");
      var rekordszam = t.length - 1;
      if (rekordszam == 1) {
        var k = t[i].split("|");
        var k = t[i].split("|");
       $("#alkalmaserveny_kiir").val(k[5]);
      } else {
        console.log("It has no record yet");
        return;
      }
    }
  })
});
© www.soinside.com 2019 - 2024. All rights reserved.