Jquery 在选项元素中显示django cms子菜单
我使用django cms输出ul中显示的每个模板的子菜单。然而,我正在使网站响应,我希望能够在选择下拉列表中输出内容。这里是文档-它提到使用自定义模板,但我真的不需要这样做 我想这样输出子菜单:Jquery 在选项元素中显示django cms子菜单,jquery,html,css,django,django-cms,Jquery,Html,Css,Django,Django Cms,我使用django cms输出ul中显示的每个模板的子菜单。然而,我正在使网站响应,我希望能够在选择下拉列表中输出内容。这里是文档-它提到使用自定义模板,但我真的不需要这样做 我想这样输出子菜单: <select> <option> Home </option> </select> 家 而不是 <ul> <li> Home </li> </ul> 家 任何帮助都将不胜感激 正如您自己所
<select>
<option> Home </option>
</select>
家
而不是
<ul>
<li> Home </li>
</ul>
- 家
任何帮助都将不胜感激 正如您自己所说,文档告诉您使用自定义模板,这正是您在本例中应该做的
<select>
{% show_sub_menu 1 "option_menu.html" %}
</select>
{%show_sub_menu 1“option_menu.html”%}
然后在“option_menu.html”中:
{children%}
{{child.get_menu_title}
{%endfor%}
请注意,这将只显示一级子菜单,有关更多信息,请检查
{%if child.children%}
,如果它是True
,请按照您认为最好的方式进行操作。谢谢您的回复。实际上,我已经用一些JS实现了这一点。我已将
标记转换为
以下是代码:
<script type="text/javascript">
$(document).ready(function(){
$('.subnav').each(function() {
$(this).find('a').each(function() {
var $option = $('<option />');
$option.attr('value', $(this).attr('href')).html($(this).html());
$("#mobileNav").append($option);
});
});
$("#mobileNav").change(function(){
window.location.href = $(this).val();
});
});
</script>
$(文档).ready(函数(){
$('.subnav')。每个(函数(){
$(this).find('a').each(function(){
var$期权=$('');
$option.attr('value',$(this.attr('href')).html($(this.html());
美元(“#mobileNav”)。追加($期权);
});
});
$(“#mobileNav”).更改(函数(){
window.location.href=$(this.val();
});
});
我现在会尝试你的解决方案,因为它更干净,但是上面的代码在将来可能对其他人很方便
再次感谢
<script type="text/javascript">
$(document).ready(function(){
$('.subnav').each(function() {
$(this).find('a').each(function() {
var $option = $('<option />');
$option.attr('value', $(this).attr('href')).html($(this).html());
$("#mobileNav").append($option);
});
});
$("#mobileNav").change(function(){
window.location.href = $(this).val();
});
});
</script>