js實現select跳轉功能代碼
更新時間:2014年10月22日 17:04:44 投稿:whsnow
實現select跳轉的方法有很多,本例為大家介紹的是js實現的,通過location.href獲取跳轉地址,需要的朋友可以看看
js簡單實現select跳轉功能:代碼如下
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="selectBox">
<select class="toSlt">
<option >全部分類的商品</option>
<option >普通車床</option>
<option >回轉車床</option>
<option >普通車床</option>
<option >回轉車床</option>
</select>
</div>
<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function(){
var $body = $('body');
$body.on('change', 'select:has(option[href])', function(e) {
var _this = $(this),
_href = _this.find('option:selected').attr('href');//獲取要跳轉的地址
location.href = _href; //跳轉
})
})
</script>
</body>
</html>

