前言
最近前端使用的比较多,我这边简单的记录一下我这边需要用的的一个小技巧吧。
代码示例
//简单示例
$("#selectBox option:selected").each(function () {
console.log($(this).val())
})
//我调整过的 小小的包装一下
function GetSelectValue(id) {
var ids = "0";
$("#" + id + " option:selected").each(function () {
if (ids == "0") {
ids = $(this).val();
}
else { ids += "," + $(this).val(); }
})
return ids;
}
//从一个select 添加到另一个select
function addCos() {
var src = document.getElementById('fileinfo');
var dest = document.getElementById('sendFile');
for (var i = 0; i < src.options.length; i++) {
if (src.options[i].selected) {
var exist = false;
//校验是否重复
for (var j = 0; j < dest.options.length; j++) {
if (dest.options[j].value == src.options[i].value) {
exist = true;
break;
}
}
if (!exist) {
//新建一个option
var opt = document.createElement('OPTION');
opt.value = src.options[i].value;
opt.text = src.options[i].text;
opt.selected = true;
dest.options.add(opt);
}
}
}
}
//从selectz中移除信息
function delCos() {
var dest = document.getElementById('sendFile');
for (var i = dest.options.length - 1; i >= 0; i--) {
if (dest.options[i].selected) {
dest.options[i] = null;
}
}
}
说明
这个就是随笔记录一下(手动机智)