开发者

<select> menu navigation with Wordpress

I am trying to convert the 'list pages' function in Wordpress into a dynamic select menu navigation (like the first example here: http://lab.artlung.com/dropdown/). I have tried converting wp_list_pages using js with this code:

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

});

This works converting it, but doesn't allow me to insert the required:

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

Am I able to drop this into the above function, or is there a better way of going about this?

Any help开发者_运维百科 would be great.

<-- edit --> the below function works correctly:

$("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);
});

});


Why don't you use $select.change(function() { window.open($select.find(':selected').val(), '_top'); });?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜