【发布时间】:2010-06-01 14:31:16
【问题描述】:
当在相邻的选择框中选择了该选项时,我试图弄清楚如何从选择框中删除选项。基本上,用户可以选择通过选择框在此处添加多条记录,但我想删除他们可用的选项列表,例如,他们不能在两个选择框中输入相同的值。
单击“添加更多”按钮时,我会淡入下一个选择框容器。 PHP 生成了许多选择框,我使用 JS 将它们隐藏起来。每个选择框都有一个附加到 ID 的唯一编号,因此我想访问那些包含字符串“other_pet_types”的选择框,然后我想遍历当前可见的选择框并构建一个已选择值的数组,然后我将从新显示的选择框中的选项列表中删除它。
这是我目前所拥有的,但这绝对是不对的 - 我无法让 ID 的初始测试正常工作。
任何指针都非常感谢,因为我意识到我目前的标记很宽泛!
var vals = new Array();
//build array with currently selected options
$('p.mult_entries select').each(function(){
vals += $(this).val();
});
$("p.mult_entries:hidden:first").fadeIn("slow", function() {
$(this).find(('select').attr('id').indexOf('other_pet_types') > 0).each(function(){
console.log($(this).val()); //as expected prints nothing - need to iterate through the options of the above select
//once i extract the correct values, iterate through new select box and use inArray to remove options where that value already exists in one of previous select boxes
});
});
【问题讨论】: