Php <;选择>;使用Wordpress进行菜单导航
我试图将Wordpress中的“列表页面”功能转换为动态选择菜单导航(如这里的第一个示例:)。我尝试过使用js转换wp_列表_页面,代码如下:Php <;选择>;使用Wordpress进行菜单导航,php,javascript,wordpress,function,Php,Javascript,Wordpress,Function,我试图将Wordpress中的“列表页面”功能转换为动态选择菜单导航(如这里的第一个示例:)。我尝试过使用js转换wp_列表_页面,代码如下: $(function() { $('ul.selectdropdown').each(function() { var $select = $('<select />'); $(this).find('a').each(function() { var $option = $('<option />
$(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);
});
我能把它放到上面的函数中吗,或者有更好的方法吗
任何帮助都会很好
以下功能正常工作:
$("ul.selectdropdown").show();
$(函数(){
$('ul.selectdropdown')。每个(函数(){
变量$select=$('')
$(this).find('a').each(function(){
var$期权=$('');
$option.attr('value',$(this.attr('href')).html($(this.html());
$select.append($option);
$select.change(function(){window.open($select.find(':selected').val(),''u top');});
});
$(此).replaceWith($select);
});
})) 为什么不使用
$select.change(函数(){window.open($select.find(':selected').val(),'u top');})代码>?我对js不太在行-我已经尝试实现了这一点,但不断出现“$select not defined”错误。
$("ul.selectdropdown").show();
$(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);
});