How to disable multiple select options

只愿长相守 提交于 2019-12-02 04:08:16

You can just hide them :

var ary = [3, 4, 5];
$('[name=smjer] option').filter(function () {
    return ($.inArray(parseInt(this.value), ary) > -1);
}).hide();

and when again required show it:

var ary = [3, 4, 5];
$('[name=smjer] option').filter(function () {
    return ($.inArray(parseInt(this.value), ary) > -1);
}).show();

To make it even better, you can do this:

var ary = [3, 4, 5];

// Get the options to be hidden/shown
var $options = $('[name=smjer] option').filter(function () {
    return ($.inArray(parseInt(this.value), ary) > -1);
});

// Hide the options
$options.hide();

// Show the options
$options.show();
saidozcan

Also you can disable them:

var ary=[3,4,5];
$('[name=smjer] option').filter(function(){
    return ($.inArray(parseInt(this.value),ary) >-1);
}).prop('disabled', true);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!