Jquery on Input does not work with dynamically inserted value

I am trying to warn a value using jquery when it is generated from javascript code, the value is generated in the input field, the problem is that jquery cannot detect changes, the commands I tested are "change, input", but when I manually inject triggers jquery values

code example:

dynamically generated in javascript and placed / inserted in the input field, the value is not manually generated by JavaScript:

document.getElementById("displayDID").value = DisplayName ;

HTML:

<input type="text" id="displayDID" />

JQuery

$('#displayDID').on("input" ,function() {
            var work = $(this).val();
            alert(work);
        });

id = "displayDID" changes, but jquery cannot detect it after execution.

sample script http://jsfiddle.net/SU7bU/1/

+4
3
add trigger to it

$('#gen').on('click',function() {
    $('#field').val('val').trigger("change");
});


$(document).on("change",'#field' ,function() {
    var work = $(this).val();
    alert(work);

});

http://jsfiddle.net/ytexj/

+1

, script, . . :

$(document).ready(function(){
 $('#displayDID').on("input" ,function() {
        var work = $(this).val();
        alert(work);
    });
})

:

$(document).on("input",'#displayDID' ,function() {
        var work = $(this).val();
        alert(work);
    });
0

, , . keyup, 3350, 4 , , 1 .

$(document).ready(function() {
var interval;
	$("#variazioneAnticipo").on("input", function() {
		var variazioneAnticipo = $("#variazioneAnticipo").val();
		clearInterval(interval);
    interval = setTimeout(function(){ showValue(variazioneAnticipo) }, 1000);
	});
});

function showValue(value) {
			alert("ANTICIPO VARIATO: " + value);
}
<input id="variazioneAnticipo" class="rightAlligned form-control" style="width: 60%" type="number" step="0.01" min="0" value="3" />
Hide result

, - , setTimeout 1 , , timeOut triiger, 1 1 .

, : D

0

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


All Articles