2014-10-06 65 views
1

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

在这里它的代码,我想这样的事情是缺少,但不知道在哪里添加它
选择的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; 

回答

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事件添加到选择元素,该元素发送作为参数到一个将要将用户重定向到选定值的js函数。

+0

好吧谢谢你的帮助。会添加这个。 – therethere 2014-10-07 13:30:10