无法在输入元素上输入

Can not give input on input elements

问题:无法在输入字段中输入内容

// Make the DIV element draggable:
dragElement(document.getElementById("mydiv"));

function dragElement(elmnt) {
  var pos1 = 0,
    pos2 = 0,
    pos3 = 0,
    pos4 = 0;
  if (document.getElementById(elmnt.id + "header")) {
    // if present, the header is where you move the DIV from:
    document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
  } else {
    // otherwise, move the DIV from anywhere inside the DIV:
    elmnt.onmousedown = dragMouseDown;
  }

  function dragMouseDown(e) {
    e = e || window.event;
    e.preventDefault();
    // get the mouse cursor position at startup:
    pos3 = e.clientX;
    pos4 = e.clientY;
    document.onmouseup = closeDragElement;
    // call a function whenever the cursor moves:
    document.onmousemove = elementDrag;
  }

  function elementDrag(e) {
    e = e || window.event;
    e.preventDefault();
    // calculate the new cursor position:
    pos1 = pos3 - e.clientX;
    pos2 = pos4 - e.clientY;
    pos3 = e.clientX;
    pos4 = e.clientY;
    // set the element's new position:
    elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
    elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  }

  function closeDragElement() {
    // stop moving when mouse button is released:
    document.onmouseup = null;
    document.onmousemove = null;
  }
}
#mydiv {
  width: 50%;
  position: absolute;
}

#mydivheader {
  padding: 1px;
  cursor: move;
  z-index: 10;
  color: rgb(211, 211, 211);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>


<!-- Draggable DIV -->
<div id="mydiv" class="mydiv">
  <!-- Include a header DIV with the same name as the draggable DIV, followed by "header" -->
  <div id="mydivheader" class="card">
    <div class="card-body">
      <div class="row">
        <div class="col-sm-10">
          <div class="row">
            <div class="col">
              <input type="text" class="form-control" placeholder="Titel toevoegen">
            </div>
          </div>
          <br>
          <div class="row">
            <div class="col-sm-8">
              <input type="date" id="date_start" class="form-control">
            </div>
            <div class="col-sm-2">
              <input type="time" id="time_start" class="form-control">
            </div>
            <div class="col-sm-2">
              <input type="time" id="time_end" class="form-control">
            </div>
          </div>
          <br>
          <div class="row">
            <div class="col">
              <textarea class="form-control" rows="6" placeholder="Beschrijving...."></textarea>
            </div>
          </div>
          <br>
          <div class="row">
            <div class="col">
              <input type="submit" class="btn btn-primary btn-block" value="opslaan">
            </div>
          </div>
        </div>
        <div class="col-sm-2">

          <button id="hide_card" onclick="hide(event)" class="btn btn-danger">X</button>
        </div>
      </div>
    </div>
  </div>
</div>

使用 HTML5 拖动事件来执行拖放功能。在这里,您通过使用 event.preventDefault 禁用了鼠标交互。如果您删除 event.preventDefault,那么您将能够在那里输入。使用上面的脚本,您可以使用制表符在表单中移动和键入。