<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模擬選擇項左邊移動到右邊的功能</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style>
.li_select_color {
background: #666;
}
.move {
height: 230px;
}
.move .moveL, .move .moveM, .move .moveR {
float: left;
}
.move .moveM {
margin: 0 10px;
padding-top: 80px;
}
.move .select_box {
border: 1px solid #bcbcbc;
height: 155px;
width: 250px!important;
overflow-y: auto;
margin: 0;
}
.move .select_box li{
padding-top:2px;
padding-bottom:2px;
cursor : pointer;
list-style : none;
margin-left : -40px;
}
</style>
</head>
<body>
<div class="move">
<div class="moveL">
<div>未選擇項</div>
<ul class="select_box">
<li value="1"><span>選項1</span></li>
<li value="2"><span>選項2</span></li>
<li value="3"><span>選項3</span></li>
<li value="4"><span>選項4</span></li>
<li value="5"><span>選項5</span></li>
</ul>
<input type="button" value="移入所有>>" id="selectAll">
</div>
<div class="moveM">
<input type="button" value=">>" id="select"> <br>
<input type="button" value="<<" id="unSelect">
</div>
<div class="moveR">
<div>已選擇項</div>
<ul class="select_box">
</ul>
<input type="button" value="<<移出所有" id="unSelectAll">
</div>
<div></div>
</div>
<script type="text/javascript">
<!--點擊移入按鈕-->
$("#select").click(function(){
$(".moveL .select_box li").each(function(){
if($(this).hasClass("li_select_color")){
$(".moveR .select_box").append($(this));
$(this).removeClass("li_select_color");
}
});
});
<!--點擊移出按鈕-->
$("#unSelect").click(function(){
$(".moveR .select_box li").each(function(){
if($(this).hasClass("li_select_color")){
$(".moveL .select_box").append($(this));
$(this).removeClass("li_select_color");
}
});
});
<!--點擊移入所有按鈕-->
$("#selectAll").click(function(){
$(".moveL .select_box li").each(function(){
$(".moveR .select_box").append($(this));
$(this).removeClass("li_select_color");
});
});
<!--點擊移出所有按鈕-->
$("#unSelectAll").click(function(){
$(".moveR .select_box li").each(function(){
$(".moveL .select_box").append($(this));
$(this).removeClass("li_select_color");
});
});
<!--點擊選擇項-->
$(".select_box li span").click(function () {
if ($(this).parent().hasClass("li_select_color")) {
$(this).parent().removeClass("li_select_color");
} else {
$(this).parent().addClass("li_select_color");
}
});
</script>
</body>
</html>
模擬選擇項左邊移動到右邊的功能
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.