Для запрета Попробуйте это:
$("#list>optgroup>option[value='1']").attr('disabled','disabled');
Удалить Отключить Попробуйте следующее:
$("#list>optgroup>option[value='1']").removeAttr('disabled');
my_string.substring(0, my_string.length - 1)
+ String.fromCharCode(my_string.charCodeAt(my_string.length - 1) + 1)
// Это вернет A для Z и a для z.
function nextLetter(s){
return s.replace(/([a-zA-Z])[^a-zA-Z]*$/, function(a){
var c= a.charCodeAt(0);
switch(c){
case 90: return 'A';
case 122: return 'a';
default: return String.fromCharCode(++c);
}
});
}
Вот функция, которая делает то же самое (за исключением только заглавных букв, но это легко изменить), но использует slice
только один раз и является итеративным, а не рекурсивным. В быстром тесте он примерно в 4 раза быстрее (что актуально только в том случае, если вы действительно интенсивно его используете!).
function nextString(str) {
if (! str)
return 'A' // return 'A' if str is empty or null
let tail = ''
let i = str.length -1
let char = str[i]
// find the index of the first character from the right that is not a 'Z'
while (char === 'Z' && i > 0) {
i--
char = str[i]
tail = 'A' + tail // tail contains a string of 'A'
}
if (char === 'Z') // the string was made only of 'Z'
return 'AA' + tail
// increment the character that was not a 'Z'
return str.slice(0, i) + String.fromCharCode(char.charCodeAt(0) + 1) + tail
}
Более полное решение, которое получает следующую букву в соответствии с тем, как MS Excel нумерует его столбцы ... A B C ... Y Z AA AB ... AZ BA ... ZZ AAA
Это работает с маленькими буквами, но вы можете легко расширить его и для заглавных букв.
getNextKey = function(key) {
if (key === 'Z' || key === 'z') {
return String.fromCharCode(key.charCodeAt() - 25) + String.fromCharCode(key.charCodeAt() - 25); // AA or aa
} else {
var lastChar = key.slice(-1);
var sub = key.slice(0, -1);
if (lastChar === 'Z' || lastChar === 'z') {
// If a string of length > 1 ends in Z/z,
// increment the string (excluding the last Z/z) recursively,
// and append A/a (depending on casing) to it
return getNextKey(sub) + String.fromCharCode(lastChar.charCodeAt() - 25);
} else {
// (take till last char) append with (increment last char)
return sub + String.fromCharCode(lastChar.charCodeAt() + 1);
}
}
return key;
};