js 有助于模糊处理

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

嘿所有坦克的拳头帮助 我正在一个网站上工作,但现在我有一个问题是我可以更改拳头输入而不是 sescont one whitdout 触发 on brur 我希望当我点击输入之外时它会触发 ajex,但是当我点击输入时我可以改变它

如果 ai cude 帮助我,我已经尝试过,但它不够聪明:) 我的代码:

let shiftId = 0;
let userId = 0;
let date = 0;
$(document).ready(function () {
  $(document).on("dblclick", ".shift", function () {
    let cell = $(this);
    shiftId = cell.find(".shift-value").attr("id");
    userId = cell.find(".shift-value").attr("user-id");
    date = cell.find(".shift-value").attr("date");
    console.log(userId);
    let currentValue = cell.text().trim();
    let inputs =
      '<input type="time" class="start" value="' +
      currentValue.split("-")[0] +
      '"> - <input type="time" class="end" value="' +
      currentValue.split("-")[1] +
      '">';
    cell.html(
      "<div class='shift-value' date=" +
        date +
        " user-id=" +
        userId +
        "  id=" +
        shiftId +
        ">" +
        inputs +
        "</div>"
    );
    cell.find(".start").focus();
  });

  $(document).on("blur", ".shift input", function () {
    let cell = $(this).parent();
    let start = cell.find(".start").val();
    let end = cell.find(".end").val();
    console.log(shiftId);
    let currentValue = start + "-" + end;

    if (currentValue !== "00:00-00:00") {
      // Create new shift if it was previously empty
      cell.html(currentValue);
      $.ajax({
        url: "rooster/create_shift.php",
        method: "POST",
        data: {
          start_time: start,
          date: date,
          end_time: end,
          user_id: userId,
          shiftId: shiftId,
        },
        success: function (response) {
          console.log(response);
        },
        error: function (xhr, status, error) {
          console.error(xhr.responseText);
        },
      });
      return;
    } else if (currentValue == "00:00-00:00") {
      // Delete shift if it was previously not empty
      cell.html(currentValue);
      $.ajax({
        url: "rooster/delete_shift.php",
        method: "POST",
        data: {
          shift_id: shiftId,
        },
        success: function (response) {
          console.log(response);
        },
        error: function (xhr, status, error) {
          console.error(xhr.responseText);
        },
      });
    } else {
      // Reset cell to previous value
      cell.html(currentValue);
    }
  });
});
javascript php jquery ajax
© www.soinside.com 2019 - 2024. All rights reserved.