Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何删除输入字段后的输入字段';它被清空了_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何删除输入字段后的输入字段';它被清空了

Javascript 如何删除输入字段后的输入字段';它被清空了,javascript,jquery,html,Javascript,Jquery,Html,我通过使用答案中的一个示例,在击键时添加输入字段。这是我的。如果用户从字段中删除内容,我会尝试各种方法来删除字段,这样总是有一些字段包含一些内容,最后一个字段是空的,可以添加更多内容,但我就是找不到解决方案 代码如下: $(document.body).on("input", ".external-media-input:last", function () { var inputID = (parseInt($(this).attr('id')) + 1); $(".input

我通过使用答案中的一个示例,在击键时添加输入字段。这是我的。如果用户从字段中删除内容,我会尝试各种方法来删除字段,这样总是有一些字段包含一些内容,最后一个字段是空的,可以添加更多内容,但我就是找不到解决方案

代码如下:

$(document.body).on("input", ".external-media-input:last", function () {
    var inputID = (parseInt($(this).attr('id')) + 1);
    $(".input_fields_wrap").append('<div><input class="external-media-input" id="' + inputID + '" name="external_media[]" type="text"/></div>');
});
$(document.body).on(“输入”,“.external media input:last”,函数(){
var inputID=(parseInt($(this.attr('id'))+1);
$(“.input\u fields\u wrap”).append(“”);
});
您可以使用或

您可以使用或

您也可以在('keyup')上使用

这是您的小提琴:

您也可以在('keyup')上使用


这是您的小提琴:

以您的风格再添加一个事件:

$(document.body).on("input", ".external-media-input", function () {
  if (!$(this).val())
  {
   $(this).remove();
  }
});

在您的样式中,再添加一个事件:

$(document.body).on("input", ".external-media-input", function () {
  if (!$(this).val())
  {
   $(this).remove();
  }
});

remove field if user deletes content from it
这不清楚?你的意思是如果输入变为空?
remove field if user deletes content from it
这不清楚?你的意思是如果输入变为空?
$(document.body).on("input", ".external-media-input", function () {
  if (!$(this).val())
  {
   $(this).remove();
  }
});