您的位置:首页 > Web前端 > JQuery

jquery select 删除 增加节点

2014-03-20 21:09 483 查看
$(document).ready(function() {
var sleft = $('#sleft');
var sright = $('#sright');
var bleft = $('#bleft');
var bright = $('#bright');
bleft.bind('click', function() {
if (sleft.find("option:selected").text() != "") {
if ($('#sleft option').size() <= 0) {
$('#sleft').attr("disabled", true);
} else {
if ($('#sleft option:selected').length >1) {
$('#sleft option:selected').each(function(i, data) {
sright.append(data);
});
} else{
var a = sleft.find("option:selected").text();
var b = sleft.find("option:selected").val();
sleft.find("option:selected").remove();
sright.append("<option value="+b+">" + a + "</option>");
}
}
}

});

bright.bind('click', function() {
if (sright.find("option:selected").text() != "") {
if ($('#sright option').size() <= 0) {
$('#sright').attr("disabled", true);
} else {
if (('#sright option:selected').length >1) {
$('#sright option:selected').each(function(i, data) {
sleft.append(data);
});
} else{

var c = sright.find("option:selected").text();
var d = sright.find("option:selected").val();
sright.find("option:selected").remove();
sleft.append("<option value="+c+">" + d + "</option>");
}
}
}

});
});
<div>
<div style="float: left;">
<select multiple="multiple" style="width:70px;" id="sleft">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
<div style="float: left">
<div>
<input id="bleft" type="button" style="float: left" value=">>" />
</div>
<div>
<input id="bright" type="button" style="float: left" value="<<" />
</div>
</div>
<div style="float: left">
<select multiple="multiple" id="sright" style="width:70px;">
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: