JavaScript 實(shí)現(xiàn)同時(shí)選取多個(gè)時(shí)間段的方法
本文介紹了JavaScript 實(shí)現(xiàn)同時(shí)選取多個(gè)時(shí)間段的方法,分享給大家,具體如下:
<template>
<div>
<ul>
<li
v-for="(item,index) in timeLine.idList"
:key="index"
iselected="0"
@mousemove="item.id != undefined ? move_li($event) : ''"
@mousedown="item.id != undefined ? down_li() : ''"
@mouseup="item.id != undefined ? up_li() : ''"
:id="item.id != undefined ? item.id : ''"
>
<div :id="item.id != undefined ? item.id : ''" iselected="0"></div>
</li>
</ul>
<div class="num">
<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span>
<span>10</span>
<span>11</span>
<span>12</span>
<span>13</span>
<span>14</span>
<span>15</span>
<span>16</span>
<span>17</span>
<span>18</span>
<span>19</span>
<span>20</span>
<span>21</span>
<span>22</span>
<span>23</span>
<span>24</span>
</div>
</div>
</template>
<script>
export default {
data() {
return {
timeLine: {
flag: 0,
preid: -1,
idList: [
{},
{ id: 0 },
{},
{ id: 1 },
{},
{ id: 2 },
{},
{ id: 3 },
{},
{ id: 4 },
{},
{ id: 5 },
{},
{ id: 6 },
{},
{ id: 7 },
{},
{ id: 8 },
{},
{ id: 9 },
{},
{ id: 10 },
{},
{ id: 11 },
{},
{ id: 12 },
{},
{ id: 13 },
{},
{ id: 14 },
{},
{ id: 15 },
{},
{ id: 16 },
{},
{ id: 17 },
{},
{ id: 18 },
{},
{ id: 19 },
{},
{ id: 20 },
{},
{ id: 21 },
{},
{ id: 22 },
{},
{ id: 23 },
{}
]
}
};
},
methods: {
down_li(e) {
this.timeLine.flag = 1;
},
up_li() {
this.timeLine.flag = 0;
this.timeLine.preid = -1;
},
move_li(e) {
if (this.timeLine.flag == 0) {
return;
}
var id = e.target.getAttribute('id');
if (id == undefined) {
return;
}
id = parseInt(id);
// 避免重復(fù)獲取 ID,每個(gè)時(shí)間段都只獲取一次 ID
if (this.timeLine.preid == id) {
return;
}
// 避免滑動(dòng)時(shí)閃爍
this.timeLine.preid = id;
var iselected = $('#' + id).attr('iselected');
if (iselected == 1) {
$("#"+id).children('div').css('background-color','');
$("#"+id).attr('iselected', '0');
} else {
$("#"+id).children('div').css('background-color','#3bbe9b');
$("#"+id).attr('iselected', '1');
}
},
// 處理提交至后臺(tái)數(shù)據(jù)的時(shí)間格式為 start : end
timeLineSub() {
var preid = -1;
var start;
var count = 0;
var timeArr = [];
$('li[iselected=1]').each(function(index, value) {
var id = value.id;
if (preid == -1) {
preid = id;
start = id;
count++;
return;
}
if (preid == id - 1) {
count++;
} else {
if (count > 0) {
timeArr.push(start + ':' + count);
}
start = id;
count = 1;
}
preid = id;
});
timeArr.push(start + ':' + count);
this.timeRange = timeArr.join(',');
}
}
};
</script>
<style lang="less" scoped>
html,
body {
margin: 0;
padding: 0;
ul {
height: 20px;
margin-bottom: 0px;
padding: 10px 19px;
li {
cursor: pointer;
list-style: none;
float: left;
height: 20px;
padding: 6px 0;
}
li:nth-child(even) {
div {
width: 28px;
height: 5px;
margin-top: 2px;
background-color: rgb(232, 234, 236);
}
}
li:nth-child(odd) {
div {
width: 7px;
height: 7px;
border-radius: 50%;
margin-top: 1px;
border: 1px solid rgb(59, 190, 155);
}
}
}
.num {
height: 100%;
padding-left: 20px;
margin-top: 2px;
span {
display: inline-block;
width: 9px;
height: 7px;
font-size: 12px;
margin-right: 23px;
}
span:last-child {
margin-right: 0px;
}
}
}
</style>
效果圖如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- js 判斷當(dāng)前時(shí)間是否處于某個(gè)一個(gè)時(shí)間段內(nèi)
- JS判斷時(shí)間段的實(shí)現(xiàn)代碼
- JavaScript比較當(dāng)前時(shí)間是否在指定時(shí)間段內(nèi)的方法
- js 判斷所選時(shí)間(或者當(dāng)前時(shí)間)是否在某一時(shí)間段的實(shí)現(xiàn)代碼
- javascript實(shí)現(xiàn)根據(jù)時(shí)間段顯示問(wèn)候語(yǔ)的方法
- JavaScript計(jì)算兩個(gè)日期時(shí)間段內(nèi)日期的方法
- js控制不同的時(shí)間段顯示不同的css樣式的實(shí)例代碼
相關(guān)文章
JSON與XML的區(qū)別對(duì)比及案例應(yīng)用
這篇文章主要介紹了JSON與XML的區(qū)別對(duì)比及案例應(yīng)用的講解。本文涉及到XML和JSON優(yōu)缺點(diǎn)講解及對(duì)比,非常不錯(cuò),具有一定的參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-11-11
js檢測(cè)標(biāo)題與描述中的關(guān)鍵詞發(fā)現(xiàn)就替換或跳轉(zhuǎn)到別的頁(yè)面
這篇文章主要介紹了js檢測(cè)標(biāo)題與描述中的關(guān)鍵詞發(fā)現(xiàn)就替換或跳轉(zhuǎn)到別的頁(yè)面的實(shí)現(xiàn)方法,主要是分享它的編程思路與加密方法2021-06-06
讓html頁(yè)面不緩存js的實(shí)現(xiàn)方法
這篇文章主要介紹了讓html頁(yè)面不緩存js的實(shí)現(xiàn)方法,分析了HTML頁(yè)面緩存js的原理,并由此分析實(shí)現(xiàn)不緩存js的方法,是非常實(shí)用的技巧,需要的朋友可以參考下2014-10-10
javascript創(chuàng)建cookie、讀取cookie
這篇文章主要介紹了javascript創(chuàng)建cookie、讀取cookie的操作方法,內(nèi)容簡(jiǎn)單易學(xué),感興趣的小伙伴們可以參考一下2016-03-03
鼠標(biāo)拖動(dòng)改變DIV等網(wǎng)頁(yè)元素的大小的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇鼠標(biāo)拖動(dòng)改變DIV等網(wǎng)頁(yè)元素的大小的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07

