启用字段并允许使用键控值进行编辑

Enable fields and allow editing with keyup value

本文关键字:编辑 字段 许使用 启用      更新时间:2023-09-26

我有一个脚本,当在另一个字段中输入值时,它会启用/禁用文本字段。问题是当该字段启用时,我也希望它是可编辑的。当前脚本启用该字段,但我无法编辑文本。这是我所拥有的

<script type='text/javascript'>
$(function(){
 $('.addbut').onkeyup(function(){
      if ($(this).val() == '') {
           $('.enableOnInput').prop('disabled', true);
      } else {
           $('.enableOnInput').prop('disabled', false);
      }
 });
});
</script>

然后 html 表单有这个。

<div class="input ">
<input type="text"  class="addbut" name="location" id="location"></div>

<div class="input"><input class="enableOnInput" disabled=""type="text"id="name" name="street" required></div>

使用 .keyup( 而不是 .onkeyup(