输入未正确填充 [英] Input does not properly fill

查看:59
本文介绍了输入未正确填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击图片时我可以填写URL的第一个输入.

The first input I can fill in the URL when clicking on an image.

当我添加新的输入并单击图像时,URL会出现在按钮ADD上,该输入不在具有焦点的输入之内

When I add a new input and I click on the image, the URL appears on the button ADD not within the input with focus

https://jsfiddle.net/gislef/wyp4hzrd/

var input = '<label>Nome: <input type="text" name="images[]" /> <a href="#" class="remove">X</a></label></br>';

    $("input[name='add']").click(function( e ){
        $('#inputs_add').append( input );
    });

    $('#inputs_add').delegate('a','click',function( e ){
        e.preventDefault();
        $( this ).parent('label').remove();
    });


var focused = null;

$("input").on("focus", function() {
  focused = $(this);
})

$("img").click(function() {
  if (focused.length)
  focused.val($(this).attr("src"));
})

使用固定输入,我可以正常工作:

With fixed inputs I can work properly:

用URL图像填充输入

推荐答案

请尝试使用委托,如下所示:

please try with delegate, such as below:

var input = '<label>Nome: <input type="text" name="images[]" /> <a href="#" class="remove">X</a></label></br>';

    $("input[name='add']").click(function( e ){
        $('#inputs_add').append( input );
    });

    $('#inputs_add').delegate('a','click',function( e ){
        e.preventDefault();
        $( this ).parent('label').remove();
    });


var focused = null;

$(document).delegate("input", "focus", function() {
  focused = this;
  console.log(focused);
});

$("img").click(function() {
  if ($(focused).length)
  $(focused).val($(this).attr("src"));
});

这篇关于输入未正确填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆