将< div>在< td>内部动态地使用Jquery(vai xml解析) [英] Putting <div> inside <td> dynamically using Jquery (vai xml parsing)
问题描述
我需要获取我正在内部创建的div的ID 我的代码是:
i need to get id of div which i am creating inside a my code is:
tab_Div = $ ('#id_of_table')
$(xml).find('something').each(function(i){
value1 = $(this).attr('some_attribute');
newID = "divID_"+i;
var my_row = $('<tr><td>'+value1+'</td><td><div id="'+newID+'"></div></td></tr>').appendTo(tab_Div);
drawBar(value1,newID);
//This function draws progressbar of "value1" in the div whose id is "newID"
});
理论上,此函数应在具有两个单元格的表中添加一行 1.哪个显示值 2.该值的进度栏.
theoretically, this function should add a row to a table having two cells 1. which display value 2. progressbar of that value.
但是我认为,它的'div'的'id'有问题.并且"newID"是不是任何obj的'id'的字符串
but i think , it has a problem with 'id' of 'Div'. and "newID" is a string not 'id' of any obj
有人可以帮我吗?
请告诉我如何绘制所需的表格(即在一个单元格中使用进度条)
can anybody help me on this ???
pls tell me how can i draw desired table (i.e. with progressbar in one cell)
drawBar()的代码
code of drawBar()
function drawBar(no,eid)
{
$(eid).progressbar({value: no});
$(eid).css({background: '#99FF66'});
$(eid+" > div").css({background: '#009900'});
$(eid+" > div").css({border: 'none'});
}
drawbar函数只是将一个jqueryUI进度条绘制到DIv中,它在"eid"处接收
drawbar function just draws a jqueryUI progress bar into DIv which it receives at "eid"
推荐答案
我看过您的代码,发现您尚未关闭td中的div标签.
不仅不关闭div标签,而且您还传递了错误的表tab_Div
变量,而您传递了tab_div
hi i have seen your code and found that you have not closed the div tag inside your td
not only the div tag is not closed but u have also passed wrong variable of table tab_Div
you have passed tab_div
tab_Div = $ ('#id_of_table')
$(xml).find('something').each(function(i){
value1 = $(this).attr('some_attribute');
newID = "divID_"+i;
var my_row = $('<tr><td>'+value1+'</td><td><div id="'+newID+'" ></div></td></tr>').appendTo(tab_Div);
drawBar(value1,newID);
评论后
以下是代码:
<body>
<table id="id_of_table" style="width:50%; border:1px solid red; float:left" >
</table>
<script type="text/javascript" >
$(document).ready(function(){
tab_Div = $ ('#id_of_table');
for (var i =1; i<=10; i++){
value1 = "test";
newID = "divID_"+i;
$('<tr><td>'+value1+'</td><td><div id="'+newID+'" >i m inside div </div></td></tr>').appendTo(tab_Div);
}
//drawBar(value1,newID);
});
</script>
</body>
上面的代码工作正常,当u将其追加到表时,为什么不将其传递给变量my_row
.在HTML页面中尝试我的代码,记得添加jQuery文件.
The above code work fine, when u are appending it to table why are you passing it to the variable my_row
not required. try my code in HTML page, remember to add jQuery file.
这篇关于将< div>在< td>内部动态地使用Jquery(vai xml解析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!