需要使用 jQuery 禁用选择框中已选择的选项。我希望它变灰,就像汇编选择 http://www.ryancramer.com/projects/asmselect/examples/example1.html.
测试我的例子here http://jsfiddle.net/RnqtL/.
//JS
$("#theSelect").change(function(){
var value = $("#theSelect option:selected").val();
var theDiv = $(".is" + value);
theDiv.slideDown().removeClass("hidden");
});
$("div a.remove").click(function () {
$(this).parent().slideUp(function() { $(this).addClass("hidden"); });
});
//HTML
<body>
<div class="selectContainer">
<select id="theSelect">
<option value="">- Select -</option>
<option value="Patient">Patient</option>
<option value="Physician">Physician</option>
<option value="Nurse">Nurse</option>
</select>
</div>
<div class="hidden isPatient">Patient <a href="#" class="remove" rel="Patient">remove</a></div>
<div class="hidden isPhysician">Physician <a href="#" class="remove" rel="Patient">remove</a></div>
<div class="hidden isNurse">Nurse <a href="#" class="remove" rel="Patient">remove</a></div>
</body>
UPDATED: 这是完成的解决方案 http://jsfiddle.net/HJMFF/。感谢帕特里克和西蒙。
将此行添加到您的change
事件处理程序
$("#theSelect option:selected").attr('disabled','disabled')
.siblings().removeAttr('disabled');
这将禁用选定的选项,并启用任何以前禁用的选项。
EDIT:
如果您不想重新启用以前的功能,只需删除这部分行:
.siblings().removeAttr('disabled');
EDIT:
http://jsfiddle.net/pd5Nk/1/ http://jsfiddle.net/pd5Nk/1/
要在单击删除时重新启用,请将其添加到您的单击处理程序中。
$("#theSelect option[value=" + value + "]").removeAttr('disabled');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)