如何在 HTML 中创建 toggle-able 输入禁用器?

How do I create a toggle-able input disabler in HTML?

如果标题没有充分描述我的问题,这就是我想要创建的:一个我可以 disable/enable 使用按钮的输入。这是我到目前为止所做的:

<!DOCTYPE html>
<html>

<head>
  <title>Toggle-able input</title>
</head>

<body>
  <input type="text" id="myFile">
  <button onclick="myFunction()">Enable/disable</button>
</body>

<script>
  function myFunction() {
    var x = document.getElementById("myFile");
    if (x.disabled === false) {
      x.disabled = true;
    } else {
      x.disabled = false;
    }
</script>

   <input type="text" id="myFile">
    <button onclick="myFunction()">Enable/disable</button>
  </body>

  <script>
    function myFunction() {
    var x = document.getElementById("myFile");

    if (x.disabled === false) {
  x.disabled = true;
}

else {
  x.disabled = false;


}
} // << You were missing this. 

  </script>

您没有正确关闭您的功能

function myFunction() {
    var x = document.getElementById("myFile");

    if (x.disabled === false) {
      x.disabled = true;
    } else {
      x.disabled = false;
    }
}
<!DOCTYPE html>
<html>
  <head>
    <title>Toggle-able input</title>
  </head>
  <body>
    <input type="text" id="myFile">
    <button onclick="myFunction()">Enable/disable</button>
  </body>

<!DOCTYPE html>
<html>
<body>

<input type="text" id="myFile">
<button onclick="myFunction()">Enable/disable</button>

<script>
var togg = true;
function myFunction() {
    document.getElementById("myFile").disabled = togg;
    togg = !togg;
}
</script>

</body>
</html>