码迷,mamicode.com
首页 > 其他好文 > 详细

城市样式选择,类宝岛眼镜城市选择

时间:2015-04-16 10:19:05      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

help.js:

(function (document) {
    window.HELP = window.HELP || {};
    HELP.redrawSelect = function () {
        $("select").each(function () {
            HELP.redrawSelectByObj($(this));
        });
    }

    HELP.redrawSelectByObj = function (obj) {
        if(!$(obj).parent().hasClass(‘selectbox‘)) {
            $(obj).wrap(‘<div class="selectbox" tag="‘ + $(obj).attr(‘id‘) + ‘" />‘);
            $(obj).after("<span class=‘selecttext‘></span><span class=‘select-arrow‘ ><a href=‘javascript:;‘ class=‘arrow‘ ></a></span>");
        }

        var val = $(obj)[0].options[$(obj)[0].selectedIndex].text;
        $(obj).next(".selecttext").text(val);
        $(obj).on(‘change‘, function () {
            var val = $(obj)[0].options[$(obj)[0].selectedIndex].text;
            $(obj).next(".selecttext").text(val);
        });
    }

})(document);

if (typeof define === "function" && define.amd) {
    define("help", [], function () {
        return HELP;
    });
}

 

html:使用area.js

<div class="select">
                    <div class="selectbox" tag="province">
                        <select id="s_province" name="s_province"></select>
                        <span class="selecttext">省/直辖市</span>
                        <span class="select-arrow"><a href="javascript:;" class="arrow"></a></span>
                    </div>
                    <div class="selectbox" tag="city">
                        <select id="s_city" name="s_city"></select>
                        <span class="selecttext">市/区</span>
                        <span class="select-arrow"><a href="javascript:;" class="arrow"></a></span>
                    </div>
</div>

 

js:

<script>
    $(function() {
        HELP.redrawSelect($(‘select‘));//此处作用是点击之后select选中的值会替换掉span中的值
    });

城市样式选择,类宝岛眼镜城市选择

标签:

原文地址:http://www.cnblogs.com/langxi/p/4431202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!