我有这个 HTML 代码:
<div class="ct-slide" style="left: 55px;">
<div class="ct-menu-text shadow" style="display: block;">
<ul>
<li rel="electronica" data-id="1" title="Electrónica">Electrónica <div class="ct-pointer-cover"></div><div class="ct-pointer"></div></li>
<li rel="hogar" data-id="3" title="Hogar">Hogar <div class="ct-pointer-cover"></div><div class="ct-pointer"></div></li>
<li rel="ropa-zapatos-y-accesorios" data-id="4" title="Ropa, Zapatos y Accesorios">Ropa, Zapatos y Accesorios <div class="ct-pointer-cover"></div><div class="ct-pointer"></div></li>
<li rel="joyas-y-relojes" data-id="5" title="Joyas y Relojes">Joyas y Relojes <div class="ct-pointer-cover"></div><div class="ct-pointer"></div></li>
<li rel="salud-y-cuidado-personal" data-id="6" title="Salud y Cuidado Personal">Salud y Cuidado Personal <div class="ct-pointer-cover"></div><div class="ct-pointer"></div></li>
<li rel="deportes-y-actividades-outdoors" data-id="7" title="Deportes y Actividades Outdoors">Deportes y Actividades Outdoors <div class="ct-pointer-cover"></div><div class="ct-pointer"></div></li>
<li rel="libros" data-id="8" title="Libros">Libros <div class="ct-pointer-cover"></div><div class="ct-pointer"></div></li>
</ul>
</div>
<div rel="electronica" class="ct-submenu shadow" style="width: 1665px; display: none;">
...
</div>
<div rel="hogar" class="ct-submenu shadow" style="width: 1665px; display: none;">
...
</div>
<div rel="ropa-zapatos-y-accesorios" class="ct-submenu shadow" style="width: 1665px; display: none;">
...
</div>
<div rel="joyas-y-relojes" class="ct-submenu shadow" style="width: 1665px; display: none;">
...
</div>
<div rel="salud-y-cuidado-personal" class="ct-submenu shadow" style="width: 1665px; display: none;">
...
</div>
<div rel="deportes-y-actividades-outdoors" class="ct-submenu shadow" style="width: 1665px; display: none;">
...
</div>
<div rel="libros" class="ct-submenu shadow" style="width: 1665px; display: none;">
...
</div>
<div title="Click para abrir" class="ct-open" style="display: none;"></div>
<div style="" title="Click para cerrar" class="ct-close"></div>
</div>
正如您所看到的,每个 LI 和 DIV 都具有相同的rel
属性,我需要通过此 AJAX 调用在正确的 DIV 元素中编写返回的 HTML,但我无法让它工作。例如,如果我将li rel="electronica"
AJAX 调用返回的内容(参见下面的代码)移到应该显示在 中div rel="electronica"
,如何?有什么帮助吗?
// begin: categories picker
var k = 1;
$(".ct-menu, .ct-menu-text").on("mouseenter", "li", function() {
var id = $(this).attr('data-id');
var next = $(this).closest("div[id]").nextAll().length;
$("#selected_category").attr("value", id);
if (next > 0) {
k = k - next;
$(this).closest("div[id]").nextAll().remove();
}
$.ajax({
type: 'GET',
url: Routing.generate('category_subcategories', {parent_id: id}),
dataType: "json",
success: function(data) {
if (data.length != 0) {
$(".ct-submenu").attr('rel').eq(id).append('<div class="product-left" id="cstep' + (k + 1) + '"><ul id="step' + (k + 1) + '"></ul></div>');
var LIs = "";
$.each(data, function(index, value) {
$.each(value, function(i, v) {
LIs += '<li><a class="step ct-sub-menu-text" data-id="' + i + '" href="#">' + v + '</a></li>';
})
});
$('#step' + (k + 1)).html(LIs);
k++;
}
}
});
});
// end: categories picker