js实现select跳转


js简单实现select跳转功能:代码例如以下

<!DOCTYPE html>
<html>
<head>
    <title></title>

</head>
<body>
    <div class="selectBox">
        <select class="toSlt">
            <option href="http://jichuang.gongchang.cn/pro-161264/">所有分类的商品</option>
            <option href="http://jichuang.gongchang.cn/">普通车床</option>
            <option href="http://jichuang.gongchang.cn/brand/">回转车床</option>
            <option href="http://jichuang.gongchang.cn/">普通车床</option>
            <option href="http://jichuang.gongchang.cn/brand/">回转车床</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>


posted @ 2017-05-02 13:33  yxysuanfa  阅读(511)  评论(0编辑  收藏  举报