当我点击黄金按钮然后点击数字1024或2024或4048时,我宁愿在创建的元素中间正确 此外,目前不需要银号和无限制的免费流量。
$(function ()
{
var groupTypes = null;
var count = 0;
var url = 'http://dl.dropboxusercontent.com/s/l5rijjpp8b784n2/Groups3?m';
$.getJSON(url, null, function (data)
{
groupTypes = data;
var $list = $('<ol id="selectable" />');
$.each(groupTypes, function (i, groupType)
{
var $li = $('<li />');
$li
.addClass('ui-widget-content')
.attr('data-index', i)
.html(groupType.Name);
$list.append($li);
$li.on('click', function ()
{
count++;
var index = $(this).attr('data-index');
$(this).parent().find('li').removeClass('ui-selected');
$(this).addClass('ui-selected');
var speeds = groupTypes[index].GroupSpeeds;
console.log(speeds);
var $speedList = $('<ol id="selectable" />');
$('.speed').remove()
$.each(speeds, function (i, speed)
{
if (speed)
{
var $speedLi = $('<li />');
$speedLi
.addClass('ui-widget-content speed')
.attr('data-index', i)
.html(speed.Speed);
$speedList.append($speedLi);
$speedLi.data('speed', speed);
$speedLi.click(function ()
{
traffic(this);
});
}
});
$('body').append($speedList);
});
});
$('#container').append($list);
});
function traffic(elem)
{
var $list = $('<ol id="selectable" />');
var groupTraffics = $(elem).data('speed').GroupTraffics;
$.each(groupTraffics, function (i, t)
{
var $li = $('<li />');
$li
.addClass('ui-widget-content')
.attr('data-index', i)
.html(t.Traffic);
$list.append($li);
$.each(groupTraffics, function (i, groupTraffic)
{
$li.on('click', function ()
{
var index = $(elem).attr('data-index');
$(this).parent().find('li').removeClass('ui-selected');
$(this).addClass('ui-selectd');
var traffics = groupTraffic[index].Traffic;
var $trafficList = $('<ol id="selectable" class="traffic" />');
$('.traffic').remove();
$.each(traffics, function (i, traffic)
{
if (traffic)
{
var $trafficLi = $('<li />');
$trafficLi
.addClass('ui-widget-content ')
.attr('data-index', i)
.html(traffic.Traffic);
$trafficList.append($trafficLi);
}
});
$('body').append($trafficList);
});
$('#container').append($list);
});
});
}
});
答案 0 :(得分:3)
看看这个例子是否有帮助。在您的流量功能中添加列表时,请将其更改为:
function traffic(elem) {
.......
$('ol:last').after($list);
}