选择选项时,下拉列表不会重定向

时间:2014-10-06 12:34:53

标签: list drop-down-menu option selected

因此,下拉菜单显示所有选项(年,月),但是当我选择它时什么都不做。该页面不会加载到正确的选项。

这里是代码,我想这样的东西不见了,但不知道在哪里添加它 选择onchange =' document.location.href = this.options [this.selectedIndex] .value;'

$elem_m = ($args['display_as_dropdown'] === true ? 'select' : 'ul');
    $elem_i = ($args['display_as_dropdown'] === true ? '<option value="%s">%s%s</option>' : '<li>    <a href="%s">%s</a>%s</li>');
$html = sprintf('<%s>', $elem_m);

foreach(array_slice(($args['order'] === 'desc' ? array_reverse($archives) : $archives), 0, ($args['limit'] === 0 ? NULL : $args['limit'])) as $archive)
{
    if($args['type'] === 'yearly')
    {
        $link = em_get_event_date_link($archive);
        $display = $archive;
    }
    else
    {
        $date = explode('-', $archive);
        $link = em_get_event_date_link($date[0], $date[1]);
        $display = $wp_locale->get_month($date[1]).' '.$date[0];
    }

    $html .= sprintf(
        $elem_i,
        $link,
        $display,
        ($args['show_post_count'] === true ? ' ('.$counts[$archive].')' : '')
    );
}

$html .= sprintf('</%s>', $elem_m);

return $html;

1 个答案:

答案 0 :(得分:0)

我创建了一个小提琴,可以帮助您实现问题的写入解决方案:

<select onchange="changePage(this)">
    <option value="http://www.google.com">Google</option>
    <option value="http://www.yahoo.com">Yahoo</option>
</select>

<script>
function changePage(e) {
    window.location = e.selectedOptions[0].value;
}
</script>

您需要将onchange事件添加到select元素,并将该元素作为参数发送到js函数,该函数将用户重定向到所选值。

相关问题