1. js对数组操作,添加元素直接可以通过push()方法,但是在删除的时候比较麻烦,下面方法删除操作将非常方便
//获取数组中特定值所在数组中的位置 Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == val) return i; } return -1; }; //删除对应值的数据 Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); //删除该数据 } };
2. jquery 操作 select元素
//获取select元素的元素个数 '(#notHasFuncs option').length; //获取select元素选中的元素个数 $('#notHasFuncs option:selected').length //遍历select元素 $("#hasFuncs option:selected").each(function () { var text = $(this).text(); var val = $(this).val(); $('#notHasFuncs').append("<option value='" + val + "'>" + text + "</option>"); $(this).remove(); delTarget(val); });