select 下option选择直接跳转到指定链接
在表单中,我们使用select来制作下拉选择项,通常只是选择option的值,但如果我们想通过选择option时,直接跳转到option的value,应该怎么操作呢?
下面就是select 下option选择直接跳转到指定链接的实现代码:
<select class="title_menu" onchange="location.href=this.value;"><option value="">请选择分类查看</option>
<?php
$args=array(
'child_of'=> get_category_root_id($cat),
'parent' => get_category_root_id($cat),
'hide_empty'=>'0',
);
$categories=get_categories($args);
foreach($categories as $category) {
//当前样式
if($cat == $category->term_id){$ons='active';}else{$ons='';}
?>
<option value="<?php echo get_category_link( $category->term_id );?>"><?php echo $category->name;?></option>
<?php }?>
</select>