问题
In an ASP.NET project, I generate N number of editboxes depending on a database query result at the launch of my app. Each textbox has an id="textNid"
with N = 0, 1 , 2...
I understood that I could not play with editboxfor in this case, so I generate some input texts at the success of an AJAX call at the launch of my app.
Something like:
for (var i = 0; i < data.length; i++) {
htmlToWrite += "<input type=\"text\" "value=\"" + data[i] + "\"" +
"id=\"text" + i + "id\"\">
...
It displays fine, I can also specify live css properties like color of the font or disabled property.
But I need to assign an onpropertychange
method to each of these input depending of their id value.
After /many) tries, I understood that $(document).ready()
would not bind this kind of method to something which doesn't exist yet.
I also read a few cases a bit similar to mine with an "on + delegate" solution, but I can't properly adapt it here.
In jQuery, how would you implement something like this:
$(document).ready(function () {
for (var i = 0; i < N; i++)
{
$("#text" + i +"id").on('input propertychange', function () {
myMethod();
}
}
...in a way which works here?
Thank you in advance.
来源:https://stackoverflow.com/questions/58058036/cant-bind-onpropertychange-to-a-dynamically-generated-input-text