Can't bind onpropertychange to a dynamically generated input text

我是研究僧i 提交于 2019-12-11 18:19:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!