将jquery ui spinner应用于动态添加的元素(apply jquery ui spinner to dynamically added elements)
我想应用jquery-ui微调器来动态添加元素。
--html代码 -
<table> <tr> <td> <div id="eachBox1"></div> </td> <td> <div id="eachBox2"></div> ... </table>
- jquery代码 -
$.ajax({ ... success: function (items) { $.each(items.d, function (idx, item) { $('#eachBox'+idx).html ( ... '<input type="text" id="qty'+idx+'" value="1"/>' ... ) } } })
我想将jquery-ui微调器应用于名称以qty开头的每个元素..所以我试过了
$(document).on("load","[id^=qty]" function () { $(this).spinner(); });
但它不起作用。 如果我将
load
事件更改为click
,则可以正常工作。 但这不是我想要的。 你有什么解决方案吗?I'd like to apply jquery-ui spinner to dynamically added elements.
--html code--
<table> <tr> <td> <div id="eachBox1"></div> </td> <td> <div id="eachBox2"></div> ... </table>
-- jquery code --
$.ajax({ ... success: function (items) { $.each(items.d, function (idx, item) { $('#eachBox'+idx).html ( ... '<input type="text" id="qty'+idx+'" value="1"/>' ... ) } } })
and i want to apply jquery-ui spinner to every element that name start with qty.. so I tried
$(document).on("load","[id^=qty]" function () { $(this).spinner(); });
But it doesn't work. If i change
load
event toclick
, it works. But it isn't what I want. Do you have any solution?
原文:https://stackoverflow.com/questions/29899263
更新时间:2022-02-22 17:02