select 多选禁用其中某个option(添加disabled)
<html>
<script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<body>
<div class="col-sm-4" id="task_stateTip">
<select class="form-control input-sm selectpicker" name="cus_product" id="cus_product" multiple title="请选择(可多选)" οnchange="Change()">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
<script type="text/JavaScript">
function Change(){
//获取被选中的option标签
var vs = $('#cus_product option:selected').val();
alert(vs);
if (vs=="volvo"){
$("#cus_product option[value='audi']").attr("disabled",true); }
}
</script>
</body>
</html>
<html>
<script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<body>
<div class="col-sm-4" id="task_stateTip">
<select class="form-control input-sm selectpicker" name="cus_product" id="cus_product" multiple title="请选择(可多选)" οnchange="Change()">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
<script type="text/JavaScript">
function Change(){
//获取被选中的option标签
var vs = $('#cus_product option:selected').val();
alert(vs);
if (vs=="volvo"){
$("#cus_product option[value='audi']").attr("disabled",true); }
}
</script>
</body>
</html>
如果引用了 bootstrap-select
- $('.ex-disable').click(function () {
- $('.disable-example option').prop('disabled', true);
- $('.disable-example').selectpicker('refresh');
- });
来自 https://blog.csdn.net/messicr7/article/details/72654168