Javascript 在没有用户事件的情况下对多个div执行Jquery函数
我有一个名为“widthz”的变量,它决定了.progress的css宽度 “widthz”的每个实例都是唯一的,因为它是根据其他“brother”div to.progress的内容确定的。现在,我的功能运行得很好,但只有当您单击.item时。我希望在没有用户事件(如单击)的情况下对.progress的每个实例执行此操作 当前代码:Javascript 在没有用户事件的情况下对多个div执行Jquery函数,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个名为“widthz”的变量,它决定了.progress的css宽度 “widthz”的每个实例都是唯一的,因为它是根据其他“brother”div to.progress的内容确定的。现在,我的功能运行得很好,但只有当您单击.item时。我希望在没有用户事件(如单击)的情况下对.progress的每个实例执行此操作 当前代码: $(document).ready(function() { $( ".budgets .item" ).click(function() {
$(document).ready(function() {
$( ".budgets .item" ).click(function() {
var limitz = $(this).children('.limit').html();
var spentz = $(this).children('.spent').html();
var widthz = spentz / limitz * 100 ;
$(this).find('.progress').css('width', widthz + '%');
});
});
将事件处理程序替换为
每个
,以迭代所有事件处理程序,并保留此
引用
$(document).ready(function() {
$( ".budgets .item" ).each(function() {
var limitz = $(this).children('.limit').html();
var spentz = $(this).children('.spent').html();
var widthz = spentz / limitz * 100 ;
$(this).find('.progress').css('width', widthz + '%');
});
});
你回答得太快了!我想我会得到这个,你的答案出来了。@AmitJoki-我打字很慢,但复制/粘贴速度很快。下次你会得到的!