点击表格td 实现某个单元格可编辑

html (elementUi中的表格,传入位置和当前值)
在这里插入图片描述
methods(生成input,将当前输入的value值等于当前单元格的值)

  handleChangeCorrectValue(index, data) {
      var target = event.target,
      $target = $(target),
      attachElement = null;
      $target.hide();
      if (attachElement != null) {
        attachElement.hide();
      }
      var input = document.createElement("input");
      input.type = "text";
      input.value = data;
      input.setAttribute("style", "width:149px;height:48px;text-align:center;box-sizing:border-box;");
      target.parentNode.insertBefore(input, target);
      input.focus();
      var _this = this;
      input.onblur = function() {
        if (this.value) {
          _this.cloneCorrectNumTableData[index].questionCorrectValue = this.value;
        } else {
          this.value = data;
        }
        _this.cloneCorrectNumTableData[index].questionCorrectValue = this.value;
        input.parentNode.removeChild(input);
        $target.show();
        if (attachElement != null) {
          attachElement.show();
        }
      };
      input.onkeypress = function(e) {
        if (e.keyCode == 13) {
          this.blur();
        }
      };
    }

猜你喜欢

转载自blog.csdn.net/qq_43246012/article/details/83090205