【问题标题】:Dropdown list not redirecting when option selected选择选项时下拉列表不重定向
【发布时间】:2014-11-30 17:15:37
【问题描述】:

所以,下拉列表显示了所有选项(年、月),但当我选择它时,它什么也不做。页面未加载到正确的选项。

这是代码,我想这样的东西不见了,但不知道在哪里添加它
select 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;

【问题讨论】:

    标签: list drop-down-menu option selected


    【解决方案1】:

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

    <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 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 2017-05-19
      相关资源
      最近更新 更多