【问题标题】:<select> menu navigation with Wordpress<select> 使用 Wordpress 进行菜单导航
【发布时间】:2011-07-08 07:19:42
【问题描述】:

我正在尝试将 Wordpress 中的“列表页面”功能转换为动态选择菜单导航(如此处的第一个示例:http://lab.artlung.com/dropdown/)。我已经尝试使用带有此代码的 js 转换 wp_list_pages:

$(function() {
$('ul.selectdropdown').each(function() {
    var $select = $('<select />');

    $(this).find('a').each(function() {
        var $option = $('<option />');
        $option.attr('value', $(this).attr('href')).html($(this).html());
        $select.append($option);
    });

    $(this).replaceWith($select);
});

});

这可以转换它,但不允许我插入所需的:

onchange="window.open(this.options[this.selectedIndex].value,'_top')"

我可以把它放到上面的函数中,还是有更好的方法来解决这个问题?

任何帮助都会很棒。

下面的函数正常工作:

$("ul.selectdropdown").show();

$(函数() { $('ul.selectdropdown').each(function() { var $select = $('');

    $(this).find('a').each(function() {
        var $option = $('<option />');
        $option.attr('value', $(this).attr('href')).html($(this).html());
        $select.append($option); 
        $select.change(function() { window.open($select.find(':selected').val(), '_top'); });
    });

    $(this).replaceWith($select);
});

});

【问题讨论】:

    标签: php javascript wordpress function


    【解决方案1】:

    你为什么不用$select.change(function() { window.open($select.find(':selected').val(), '_top'); });

    【讨论】:

    • 我不太擅长 js - 我已经尝试过实现这个,但不断收到“$select not defined”错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 2019-09-08
    • 2012-09-10
    • 2012-06-11
    相关资源
    最近更新 更多