使用Wordpress <选择>菜单导航</select>

时间:2011-07-08 07:19:42

标签: php javascript wordpress function

我正在尝试将Wordpress中的“列表页面”功能转换为动态选择菜单导航(如此处的第一个示例:http://lab.artlung.com/dropdown/)。我尝试使用以下代码转换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')"

我可以将其放入上述功能中,还是有更好的方法来解决这个问题?

任何帮助都会很棒。

&lt; - edit - &gt;以下功能正常工作:

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

$(function(){     $('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);
});

});

1 个答案:

答案 0 :(得分:2)

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