求救~js大神前台如何递归ul li读取数据 递归jsonjshtml 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 所谓的递归:/**parseLl:解析li@jdom:一个jquery 取出的dom对象*/function parseLi(jdom){ var a = {}; jdom.each(function(){ var that = $(this); a['id'] = that.attr('id'); a['nodes'] = parseUl(that.find('>ul')); }); return a;}/**parseUl:解析ul(假定同时只有一个ul)@jdom:一个jquery 取出的dom对象*/function parseUl(jdom){ if(jdom.length){ return { id:jdom.attr('id') ,nodes:parseLi(jdom.find('>li'); } }else{ return {}; }}//假定最外面的ul.id = xxx 假定 ul的子可能包含li 假定 li的子可能包含 ulvar myjson = parseUl($('#xxx')); function f(count,json) { var counts = 0; count.each(function() { var id = $(this).attr("id"); json = json + ',{'+'"id"'+':' +'"' +$(this).attr("id")+'",'+'"node"'+':' +'"'+ counts + '"}'; if ($(this).contents().filter("ul").length != 0) { f($(this).children("ul").children("li")); } else { counts += 1; } }) }大神哥哥 你来得太晚了 ~ 应该早点出来给我指点啊 这是我想了半天才想出来的~~· IE6,IE7下div被textarea挡住 帮忙找错 引入jquery插件后之前引入的插件方法变成undefined 求JS+JSP动态装载的树 一页中有两个下拉框,如果右边的框里出现了这个数,左边就不显示怎么写! 将整数转换为十六进制的字符串? 如何在一张图片上做标记? 请问怎样用JavaScript取得name参数(http://localhost/test.aspx?name=ttt) 100分求购日期输入弹出框 javascript中变量冒号方法 如data:function(){} 崩溃,checkbox 不能即时监听了? 求教提交form表单后弹出模态框?
/**
parseLl:解析li
@jdom:一个jquery 取出的dom对象
*/
function parseLi(jdom){
var a = {};
jdom.each(function(){
var that = $(this);
a['id'] = that.attr('id');
a['nodes'] = parseUl(that.find('>ul'));
});
return a;
}
/**
parseUl:解析ul(假定同时只有一个ul)
@jdom:一个jquery 取出的dom对象
*/
function parseUl(jdom){
if(jdom.length){
return {
id:jdom.attr('id')
,nodes:parseLi(jdom.find('>li');
}
}else{
return {};
}
}//假定最外面的ul.id = xxx 假定 ul的子可能包含li 假定 li的子可能包含 ul
var myjson = parseUl($('#xxx'));
var counts = 0;
count.each(function() {
var id = $(this).attr("id");
json = json + ',{'+'"id"'+':' +'"' +$(this).attr("id")+'",'+'"node"'+':' +'"'+ counts + '"}';
if ($(this).contents().filter("ul").length != 0) {
f($(this).children("ul").children("li"));
} else {
counts += 1;
}
})
}大神哥哥 你来得太晚了 ~ 应该早点出来给我指点啊 这是我想了半天才想出来的~~·