我正在尝试将 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')"
我能把它放到上面的函数中吗,或者有更好的方法吗?
任何帮助都会很棒。
<-- edit --> 下面的函数可以正常工作:
$("ul.selectdropdown").show();
$(函数() { $('ul.selectdropdown').each(函数() { 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);
});
});
最佳答案
你为什么不使用 $select.change(function() { window.open($select.find(':selected').val(), '_top'); });
?
关于php - <select> 使用 Wordpress 的菜单导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6621205/