How to tell jQuery about added row string

I have a form that can contain a number of elements added via ajax. But when this line is added, new inputs cannot receive focus.

Trying to solve this problem, I found that they get focus if a warning is triggered during the bind function.

I was looking for answers, but I just can't get it to work. I think a “live” function may be related, but I really don't understand how to use it.

Here is my code.

$("#doogal").bind("click", function (event) {
    $.ajax({data:$("#doogal").closest("form").serialize(), dataType:"html", success:function (data, textStatus) {$("#saleitems").append(data);}, type:"get", url:"\/saleitems\/add\/" + $rows});
    $rows = $rows + 1;
//  alert("uncomment this to enable focus");
    $("#autoComplete_1").focus();       
    return false;   

});
+3
source share
2 answers

. $.ajax - . , .focus() , ajax , . , .focus() , ajax.

.focus() (, , $row) , ajax:

$("#doogal").bind("click", function (event) {
    $.ajax({data:$("#doogal").closest("form").serialize(), dataType:"html", success:function (data, textStatus) {
        $("#saleitems").append(data);
        $rows = $rows + 1;
        $("#autoComplete_1").focus();       
    }, type:"get", url:"\/saleitems\/add\/" + $rows});
    return false;   
});
+2

. AJAX, , , .

$("#doogal").bind("click", function (event) {
    $.ajax({data:$("#doogal").closest("form").serialize(), 
        dataType:"html", 
        success:function (data, textStatus) {
             $("#saleitems").append(data);

             $rows = $rows + 1;
             $("#autoComplete_1").focus();
        }, 
        type:"get", 
        url:"\/saleitems\/add\/" + $rows
    });

    return false;   

});
+1

Source: https://habr.com/ru/post/1776035/


All Articles