开发者

<select> menu navigation with Wordpress

开发者 https://www.devze.com 2023-03-19 00:05 出处:网络
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_p

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

精彩评论

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