操作代码:HTML>
select框操作function addSelect(){
var option= $('#option').val();
var text= $('#text').val();
var item = ""+text +"";
//option重复的重新添加
$("#selectList option[value='"+option+"']").remove();
$('#selectList').append(item);
}
function getAllSelect(){
// 获取到select多选框中的选项
var items = $("#selectList option");
// 遍历内容
$(items).each(function(){
var option = $(this).val();
var text = $(this).text();
alert(option + "" + text);
});
}
function getSelect(){
// 获取到select多选框选中项(可能是一个也可能是多个)
var items = $("#selectList option:selected");
// 遍历内容
$(items).each(function(){
var option = $(this).val();
var text = $(this).text();
alert(option + "" + text);
});
}
function delSelect (){
// 获取到select多选框选中项(可能是一个也可能是多个)
var items = $("#selectList option:selected");
// 遍历内容
$(items).each(function(){
var option = $(this).val();
var text = $(this).text();
$("#selectList option[value='"+option+"']").remove();
});
}
option->
text->
操作效果: