js、jq实现select 下拉选择更多

<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery ySelect Plugin Demo</title>

    <!--图标和默认样式-->
    <link rel="stylesheet" type="text/css" href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="http://cdn.bootcss.com/font-awesome/4.6.0/css/font-awesome.min.css">

    <!--核心样式-->
    <link href="css/ySelect.css" rel="stylesheet" type="text/css">

    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>


</head>

<body>

    <select id="m1" class="demo hidden" multiple="multiple">
        <option value="1">加多宝凉茶</option>
        <option value="2">饮料</option>
        <option value="3">太太乐鸡精</option>
        <option value="4">嘉士伯啤酒</option>
        <option value="5">成功图像类型</option>
        <option value="6">门店类型</option>
        <option value="7">终端类型</option>
    </select>
</body>

<script src="js/ySelect.js"></script>
<script>
    $(function() {
        $('#m1').ySelect({
            placeholder: '请先选择一些项目',
            // searchText: '搜索',
            showSearch: false,
            numDisplayed: 4,
            overflowText: '已选中 {n}项',
            isCheck: false
        });
        $("#m1").ySelectedValues(",")
    });
</script>

</html>

  

ySelect.css
.fs-wrap {
    position: relative;
    display: inline-block;
    width: 200px;
    margin: 3px;
    font-size: 12px;
    line-height: 1;
}

.fs-label-wrap {
    position: relative;
    border: 1px solid #ccc;
    cursor: default;
    color: #555;
    border-radius: 4px;
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
}

.fs-label-wrap,
.fs-dropdown {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.fs-label-wrap .fs-label {
    padding: 4px 22px 4px 8px;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
}

.fs-arrow {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid #000;
    position: absolute;
    top: 0;
    right: 4px;
    bottom: 0;
    margin: auto;
    cursor: pointer;
}

.fs-dropdown {
    /* position: absolute; */
    background-color: #fff;
    border: 1px solid #ccc;
    /*margin-top: 2px;*/
    width: 100%;
    z-index: 1000;
    border-radius: 4px;
}

.fs-dropdown .fs-options {
    max-height: 200px;
    overflow: auto;
}

.fs-search input {
    width: 90%;
    padding: 2px 4px;
    border: 0;
}

.fs-selectAll {
    float: right;
    cursor: pointer;
    margin-top: 4px;
    height: auto;
}

.fs-selectAll.selected {
    float: right;
    cursor: pointer;
    margin-top: 4px;
    height: auto;
    color: green;
}

.fs-selectAll:hover {
    background-color: #eee;
}

.fs-option,
.fs-search,
.fs-optgroup-label {
    padding: 6px 8px;
    border-bottom: 1px solid #eee;
    cursor: default;
}

.fs-option {
    cursor: pointer;
}

.fs-option.hl {
    background-color: #f5f5f5;
}

.fs-wrap.multiple .fs-option {
    position: relative;
    padding-left: 30px;
}

.fs-wrap.multiple .fs-checkbox {
    position: absolute;
    display: block;
    width: 30px;
    top: 0;
    left: 0;
    bottom: 0;
}

.fs-wrap.multiple .fs-option .fs-checkbox i {
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 14px;
    height: 14px;
    border: 1px solid #aeaeae;
    border-radius: 4px;
    background-color: #fff;
}

.fs-wrap.multiple .fs-option.selected .fs-checkbox i {
    background-color: rgb(17, 169, 17);
    border-color: transparent;
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAGCAYAAAD+Bd/7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNXG14zYAAABMSURBVAiZfc0xDkAAFIPhd2Kr1WRjcAExuIgzGUTIZ/AkImjSofnbNBAfHvzAHjOKNzhiQ42IDFXCDivaaxAJd0xYshT3QqBxqnxeHvhunpu23xnmAAAAAElFTkSuQmCC');
    background-repeat: no-repeat;
    background-position: center;
}

.fs-wrap .fs-option:hover {
    /*background-color: #f5f5f5;*/
    background: #D1F3E5;
    border-radius: 4px;
    margin-left: 0px;
    margin-right: 2px;
}

.fs-optgroup-label {
    font-weight: bold;
}

.hidden {
    display: none;
}

.fs-options::-webkit-scrollbar {
    width: 6px;
}

.fs-options::-webkit-scrollbar-track {
    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;
    -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: rgba(0, 0, 0, 0.1);
}

.fs-options::-webkit-scrollbar-thumb {
    -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: rgba(0, 0, 0, 0.2);
    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;
}

  

posted @ 2020-11-02 12:02  YH丶浩  阅读(93)  评论(0编辑  收藏  举报