在jQuery中使用.each对动态对象? [英] Using .each on dynamic objects in jQuery?

查看:138
本文介绍了在jQuery中使用.each对动态对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多问题似乎正在问这个问题,但最终他们想要的是附加.click事件而不是每个。所以这些普遍接受的答案包括 $ (body)。on(click,.selector,function(){}); ,这绝对不是我想要的。

There are lots of questions that seem to be asking this, but in the end all they want is to attach .click events and not .each and so the generally accepted answer in all of them include $("body").on("click", ".selector", function(){}); and this is definitely not what I want.

我有一些生成的输入,我需要同时更改每个的值。通常我会 $(。inputs)。each(function(){$(this).val(new-value)}; 但是,我不能因为动态方面。

I have some generated inputs and I need to change the value of each one at the same time. Normally I would $(".inputs").each(function(){$(this).val("new-value")}; or something along those lines, however, I can't because of the dynamic aspect.

那么你如何做一个 $(body)。on(每个,.inputs,function(){});

推荐答案

在setTimout中运行.each一样简单。

Actually, it's as simple as running the .each inside setTimout.

setTimeout(function(){
  $(".inputs").each(function(){$(this).val("new-value")});
}, 5000);

这篇关于在jQuery中使用.each对动态对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆