【发布时间】:2011-07-08 07:19:42
【问题描述】:
我正在尝试将 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')"
我可以把它放到上面的函数中,还是有更好的方法来解决这个问题?
任何帮助都会很棒。
下面的函数正常工作:
$("ul.selectdropdown").show();
$(函数() { $('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);
});
});
【问题讨论】:
标签: php javascript wordpress function