JQuery.html () and the variable inside

I would like to put the FLC variable inside $("#FNC").html(''); but don’t know how, what are the tips?

DEMO:

 var FLV = $("#random-input-box").val(); $("#FNC").html('<input id="random-input-box" style="width: 99px;" value="FLC" disabled="disabled" />'); 
+4
source share
2 answers

Did you mean the FLV value in the value attribute of the input field?

 var FLV = $("#random-input-box").val(); $("#FNC").html('<input id="random-input-box" style="width: 99px;" value="'+FLV+'" disabled="disabled" />'); 
+3
source

String concatenation is dangerous without input validation.

Just use .val() to set the input value, and ideally use the jQuery constructor rather than .html() to create it:

 var FLV = $("#random-input-box").val(); $('#FNC').empty(); $('<input id="random-input-box" style="width: 99px;" disabled="disabled" />') .val(FLV).appendTo('#FNC'); 
0
source

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


All Articles