简体   繁体   English

将HTML标签添加到使用Javascript通过数据库提取的项目中?

[英]Adding HTML tags to items pulled through a databse using Javascript?

I'm trying to add 'li' tags to objects I am pulling through a database, right now the results appear as unsorted 'item1 item2 item3 item3' with this code: 我正在尝试向要通过数据库提取的对象添加“ li”标签,现在结果显示为未排序的“ item1 item2 item3 item3”,其代码如下:

var XML = new Array();     
XML = xmlHttpRequest.responseXML;    
alert($(XML).find('ItemName').text());

Any advice would be appreciated, thanks 任何建议,将不胜感激,谢谢

Imagine each ItemName is an object. 想象每个ItemName是一个对象。 Each of those objects can be iterated through using the same methods you are using above 这些对象中的每一个都可以使用与上面相同的方法进行迭代

var eachItem = $(XML).find('ItemName');
$.each(eachItem, function(index,value){
  $("#someContainer").append('<li>'+$(value).text()+'</li>');
  //in the above, 'value' is our object', 'index' is the row # at which our object was found.
});

Edit - Edited to reflect needs of OP. 编辑 - 编辑以反映OP的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM