我有一个脚本,它通过隐藏选择框并在用户单击“假”div 时将其定位为一组样式 div 来替换选择框。我的目标是这样的选定项目:
targetSelect.eq(optionIndex).prop('selected');
optionIndex
是所选 div 的索引,因为它对应于隐藏的选择框选项。
上面的行没有将“selected”添加到目标选项。我知道我的目标是正确的,因为targetSelect.eq(optionIndex).addClass('selected');
将添加该类并将targetSelect.eq(optionIndex).attr('selected',"true");
选定的属性设置为 true。
我也试过:
targetSelect.prop('selectedIndex',optionIndex);
但这也不起作用。