我建议你依靠Angular
来做到这一点,并忘记了直接使用jQuery
,因为它没有必要。
你可以做的是有一个所有选项的主要列表,并为选择维护两个单独的列表。选择更改将重建列表。这里的例子不是基于你的运营商的代码,而是基于PoC的。你应该注意到的是一个选择列表中的选定选项不能成为另一个选项中的选项。
angular.module('app', [])
.controller('controller', function() {
var self = this;
self.mainList = [{
name: 'Public'
}, {
name: 'Private'
}, {
name: 'Protected'
}, {
name: 'Super'
}, {
name: 'Awesome'
}, ];
self.lists = [
[],
[]
];
self.selections = [self.mainList[0], self.mainList[1]];
self.buildList = function(which, other) {
self.lists[which] = [];
self.mainList.forEach(function(e) {
if (e.name !== self.selections[other].name) {
self.lists[which].push(e);
}
});
};
self.buildLists = function() {
self.buildList(0, 1);
self.buildList(1, 0);
};
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="controller as c" ng-init="c.buildLists()">
<label>First</label>
<select ng-model="c.selections[0]" ng-change="c.buildLists()"
ng-options="o.name for o in c.lists[0]">
</select>
<label>Second</label>
<select ng-model="c.selections[1]" ng-change="c.buildLists()"
ng-options="o.name for o in c.lists[1]">
</select>
</div>
你的想法是错误的。你不能在所有浏览器中隐藏'
如果它支持现代浏览器,我很好。如果您可以分享其他可能的选项/解决方案以满足我的要求,那将会非常有帮助。 – Nikki
对于初学者来说,缩小演示的范围只包含'