复制< div>标记每个标记的唯一ID [英] Duplicate a <div> Tag with a unique ID for each Tag

查看:80
本文介绍了复制< div>标记每个标记的唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,



我有一个包含很多进度条的数组。我稍后将这些进度条解析成一个html表。每个进度条都会得到一个不同的ID,因此每个进度条都是唯一的。这不能很好地工作:



 $。each(status, function (index){
status [index] = ' < div id =progressBar' + index + ' >< div>< / div>< / div>';
progress(百分比, #progressBar + index);
}
});





进度函数:



  function 进度(百分比,$元素){
var progressBarWidth = percent * $ element.width()/ 100 ;
$ element.find(' div')。animate({width:progressBarWidth}, 500 )。html(percent.replace(' \ r \'n ' ')+ );
}





(我知道循环在这里没有多大意义,但在我的代码中它有点不同在这种背景下不重要)



如何解决我的问题?

解决方案

。 each(status, function (index){
status [index] = ' < div id =progressBar' + index + ' > < div>< / div>< / div>';
进度(百分比, #progressBar + index);
}
});





进度函数:



 函数进度(百分比,

element){
var progressBarWidth = percent *


element.width()/ 100 ;

Hey Guys,

I have an Array with a lot of progress bars in it. I parse these progress bars into a html-table later on. Every progress bar shall get a different ID so every progress bar is unique. This doesn't work quite well:

$.each(status, function (index) {
                           status[index] = '<div id="progressBar'+ index +'"><div></div></div>';
                           progress(percent, "#progressBar" + index);
                        }
                    });



The progress-function:

function progress(percent, $element) {
                var progressBarWidth = percent * $element.width() / 100;
                $element.find('div').animate({ width: progressBarWidth }, 500).html(percent.replace('\r\n', '') + "%");
            }



(I know the loop does not make much sense here, but it's a bit different in my code which isn't important in this context)

Any suggestions how I can solve my problem?

解决方案

.each(status, function (index) { status[index] = '<div id="progressBar'+ index +'"><div></div></div>'; progress(percent, "#progressBar" + index); } });



The progress-function:

function progress(percent,


element) { var progressBarWidth = percent *


element.width() / 100;


这篇关于复制&lt; div&gt;标记每个标记的唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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